scholrly / orcid-python

A simple wrapper around the ORCID.org API.
MIT License
33 stars 11 forks source link

AttributeError - passing function rather than dict? #3

Closed cameronneylon closed 11 years ago

cameronneylon commented 11 years ago

I'm really confused by this. I had everything working just fine, just as it was supposed to according to the readme and then I somehow managed to break something. So on a clean VM running Python 2.7 I get the following and this is now what happens regardless of the system I'm running. As I say, it was working just fine which is what is confusing me:

vagrant@iPythonNotebook:/vagrant$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import orcid
[...]
>>> john = orcid.get('0000-0002-4510-0385')
>>> print john.family_name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/orcid/utils.py", line 34, in getter
    return dict_value_from_path(cur_dict, path)
  File "/usr/local/lib/python2.7/dist-packages/orcid/utils.py", line 4, in dict_value_from_path
    cur_dict = cur_dict.get(key, {})
AttributeError: 'function' object has no attribute 'get'
mhluongo commented 11 years ago

Interesting- it works fine on my end (on Python 2.7.3). I'll try a new virtualenv.

mhluongo commented 11 years ago

I think the difference is in requests version. This was addressed by https://github.com/scholrly/orcid-python/pull/2, so if you install from GitHub (pip install -e git+https://github.com/scholrly/orcid-python#egg=order-python-dev) I imagine it will work. I'll update the requirement and push the bugfix to PyPi soon.

Another way to to confirm that's the case- install an earlier version of requests (maybe pip install -U requests==1.0.4) and see whether it works. If not, please reopen this issue and we'll get it sorted out.

cameronneylon commented 11 years ago

Thanks for this and thanks for the wrapper as well! Now it's working again it's great.

Just to note, that the dev version does work as above but the suggested version of requests does not. This is because the relevant change to the requests API is between v 0.x and 1.x as per http://docs.python-requests.org/en/latest/api/#migrating-to-1-x

So the following works:

 vagrant@iPythonNotebook:~$ sudo pip install requests==0.14.2
 vagrant@iPythonNotebook:~$ sudo pip install orcid-python
 vagrant@iPythonNotebook:~$ python
 Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
 [GCC 4.6.3] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import orcid
 >>> orcid.get('0000-0002-0068-716X')
 <Author Cameron Neylon, ORCID 0000-0002-0068-716X>
 >>> 

as does:

 vagrant@iPythonNotebook:~$ sudo pip install -e git+https://github.com/scholrly/orcid-python#egg=order-python-dev
 vagrant@iPythonNotebook:~$ python
 Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
 [GCC 4.6.3] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import orcid
 >>> orcid.get('0000-0002-0068-716X')
 <Author Cameron Neylon, ORCID 0000-0002-0068-716X>
 >>> exit()
mhluongo commented 11 years ago

Ah, of course. Thanks Cameron! On May 26, 2013 6:56 AM, "Cameron Neylon" notifications@github.com wrote:

Thanks for this and thanks for the wrapper as well! Now it's working again it's great.

Just to note, that the dev version does work as above but the suggested version of requests does not. This is because the relevant change to the requests API is between v 0.x and 1.x as per http://docs.python-requests.org/en/latest/api/#migrating-to-1-x

So the following works:

vagrant@iPythonNotebook:~$ sudo pip install requests==0.14.2 vagrant@iPythonNotebook:~$ sudo pip install orcid-python vagrant@iPythonNotebook:~$ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import orcid orcid.get('0000-0002-0068-716X') <Author Cameron Neylon, ORCID 0000-0002-0068-716X>

as does:

vagrant@iPythonNotebook:~$ sudo pip install -e git+https://github.com/scholrly/orcid-python#egg=order-python-dev vagrant@iPythonNotebook:~$ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import orcid orcid.get('0000-0002-0068-716X') <Author Cameron Neylon, ORCID 0000-0002-0068-716X> exit()

— Reply to this email directly or view it on GitHubhttps://github.com/scholrly/orcid-python/issues/3#issuecomment-18461341 .