Error Using Python Requests Library - TypeError: 'dict' object is not callable
A recent task at work was to generate a Python class that could be used by developers to interact with our API. One of the methods in that class was to do a curl call to our API.
For this i used the very nice Requests Library and since our API returns output in JSON, i used the:
function to return the output. This worked fine on my Mac, but when this was tested on a Windows machine it returned the following error:
The solution, or so I thought was to use:
As documented in the Love Python blog article. This worked wonders for the Windows machine, but as a consequence, it made my Mac spit out the following:
Since Python is not one of my strongest languages, (I've only been learning it for a few days!) I have no solution as to why this is happening and how to fix it.
In the end I settled for using:
to return the output as a string, not ideal, but it works on both OS's.
If you happen to know the solution to the above, please leave a comment!
For the record I'm using Python v2.6.1 - I know v3 is available, should I consider switching?
For this i used the very nice Requests Library and since our API returns output in JSON, i used the:
r.json()
function to return the output. This worked fine on my Mac, but when this was tested on a Windows machine it returned the following error:
line 68, in doCurl
print r.json()
TypeError: 'dict' object is not callable
The solution, or so I thought was to use:
r.json
As documented in the Love Python blog article. This worked wonders for the Windows machine, but as a consequence, it made my Mac spit out the following:
<bound method Response.json of <Response [200]>>
Since Python is not one of my strongest languages, (I've only been learning it for a few days!) I have no solution as to why this is happening and how to fix it.
In the end I settled for using:
r.text
to return the output as a string, not ideal, but it works on both OS's.
If you happen to know the solution to the above, please leave a comment!
For the record I'm using Python v2.6.1 - I know v3 is available, should I consider switching?
Comments
Post a Comment