beowwwulf
beowwwulf

Reputation: 269

TypeError: 'dict' object is not callable in connecting - Arangodb - Python

I want to use pyarango-library in python to connect to arrangodb, but I cannot even get connected. Here is the code using 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

And this is the error I get:

  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

I can't find any related threads on it, can somebody help me with this?

Solution:

I first did a: pip install requests and got:

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

But it wasnt sufficient...so I had to upgrade it/force it:

    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

Now it connects, and the self.conn[etc].. I just deleted the: self. and went like this:

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

And it worked!! THANK YOU MARTIJN!!!

nb! the error I mentioned last was only because the db already existed.

Upvotes: 2

Views: 1677

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124818

Your error indicates that you are using an old requests version; response.json() became a method in requests version 1.0. Your local installation predates this.

Either you have an old release installed as an OS package, or by you yourself. You need to upgrade that package.

Upvotes: 2

Related Questions