我想使用python中的pyarango库连接到arrangeodb,但我甚至无法连接。以下是使用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
它成功了!!谢谢你MARTIJN!!!
nb!我上次提到的错误只是因为数据库已经存在。
您的错误表明您使用的是旧的requests
版本;CCD_ 3成为CCD_ 4 1.0版本中的一种方法。您的本地安装早于此。
要么你有一个旧版本作为操作系统包安装,要么你自己安装。您需要升级该软件包。