【发布时间】:2015-02-14 22:46:08
【问题描述】:
我想在 python 中使用pyarango-library 连接到 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
而且成功了!!谢谢马丁!!!
注意!我最后提到的错误只是因为db已经存在。
【问题讨论】:
-
您使用的是旧版本的
requests库。这是在 Ubuntu 上吗?是否安装了python-requests系统和0.8.x 版本? -
我不确定请求库实际上是什么。这是 kali linux/debian wheezy-base。所以我会尝试安装python-requests系统...回来
-
使用 pip install requests - 它说:成功安装 requests-2.5.1 但随后发生另一个错误:NameError: name 'self' is not defined 似乎无法识别:self.conn [等..]
-
感谢您的问题,我已更新 setup.py 以便 pyArango 现在需要请求>=2.7.0。
标签: python connection arangodb