Attribute Error trying to run Gmail API quickstart in Python

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

It looks like there might be a version mismatch problem here. How should I go about fixing it?

I've trying updating six with pip, but that doesn't do anything.

Here's the error I see:

Traceback (most recent call last):   File "./quickstart.py", line 27, in      credentials = run(flow, STORAGE, http=http)   File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper     return wrapped(*args, **kwargs)   File "/Library/Python/2.7/site-packages/oauth2client/old_run.py", line 120, in run     authorize_url = flow.step1_get_authorize_url()   File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper     return wrapped(*args, **kwargs)   File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 1827, in step1_get_authorize_url     return _update_query_params(self.auth_uri, query_params)   File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 435, in _update_query_params     parts = urllib.parse.urlparse(uri) AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse' 

回答1:

I ran into a very similar problem, albeit using a completely different API (compute engine). I ended up rolling back the google api client to the previous version - 1.3.2 - as opposed to the latest - 1.4.0. To do this, I ran:

sudo pip install -I google-api-python-client==1.3.2 

And was then able to run my code.

I'm not sure if this is the same problem, but it seems to have done the trick for me, hope this helps.



回答2:

Figured out the source of the problem -- the pre-installed OSX version of six (1.4.1) is the one loaded because its location comes first on your python path.

The version required by gmail (1.6.1) is therefore shielded and therefore never imported.

A quick fix is just to prepend the 1.6.1 installation directory to your python path, so it's loaded before the 1.4.1 version. Not the best solution, but it works.

import sys sys.path.insert(1, '/Library/Python/2.7/site-packages') 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!