Skip to main content
 首页 » 编程设计

python之类型错误 : 'dict' object is not callable in connecting之Arangodb之Python

2024年10月25日8zhengyun_ustc

我想使用 pyarango -python 中的库连接到 arrangodb,但我什至无法连接。这是使用 python 2.7 的代码:

from pyArango.connection import Connection 
 
conn = Connection() 
conn.createDatabase(name = "test_db") 
db = self.conn["test_db"] #all databases are loaded automatically into the connection and are accessible in this fashion 
collection = db.createCollection(name = "users") #all collections are also loaded automatically 
# collection.delete() # self explanatory 

这是我得到的错误:

  File "pyarango-test1.py", line 8, in 
    conn = Connection(arangoURL='http://localhost:8529') #or with just conn = Connection() 
  File "/usr/local/lib/python2.7/dist-packages/pyArango/connection.py", line 19, in init 
    self.reload() 
  File "/usr/local/lib/python2.7/dist-packages/pyArango/connection.py", line 27, in reload 
    data = r.json() 
TypeError: 'dict' object is not callable 

我在上面找不到任何相关主题,有人可以帮我解决这个问题吗?

解决方案:

我首先做了一个:pip install requests 并得到:

Requirement already satisfied (use --upgrade to upgrade): requests in /usr/lib/python2.7/dist-packages  

但这还不够......所以我不得不升级它/强制它:

    sudo pip install --upgrade requests  
    and got:  
    Collecting requests from https://pypi.python.org/packages/py2.py3/r/requests/requests-2.5.1-py2.py3-none-any.whl#md5=11dc91bc96c5c5e0b566ce8f9c9644ab Downloading requests-2.5.1-py2.py3-none-any.whl (464kB) 100% |################################| 466kB 3.6MB/s Installing collected packages: requests Found existing installation: requests 0.12.1 Uninstalling requests-0.12.1: Successfully uninstalled requests-0.12.1 
 
Successfully installed requests-2.5.1 

现在它连接了,并且 self.conn[etc].. 我刚刚删除了:self.然后像这样:

try: 
    conn.createDatabase(name = "test_db2") 
except Exception as e: 
    print "conn could not createDatabase(name = test_db)" 
    print e 

成功了!!谢谢你,马丁!!!

注意!我最后提到的错误只是因为数据库已经存在。

请您参考如下方法:

您的错误表明您使用的是旧的 requests 版本; response.json() 成为 requests version 1.0 中的一个方法.您的本地安装早于此。

要么您将旧版本安装为操作系统包,要么您自己安装。您需要升级该软件包。