18

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 <module>
    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'
abraham
  • 46,583
  • 10
  • 100
  • 152
rstackhouse
  • 2,238
  • 24
  • 28
  • try `pip install -U w3lib six` – itzMEonTV Mar 22 '15 at 04:25
  • `pip install -U w3lib six` did not work – rstackhouse Mar 25 '15 at 08:11
  • 1
    This is discussed as part of a known [issue on github](https://github.com/google/google-api-python-client/issues/100). Work arounds include downgrading to version 1.3.2 as mentioned by [Theolodus](http://stackoverflow.com/users/3249000/theolodus) or setting the PYTHONPATH variable `export PYTHONPATH=/Library/Python/2.7/site-packages` as mentioned by [jwadsack](http://stackoverflow.com/users/201911/jwadsack) – Matt Dec 29 '15 at 18:51

2 Answers2

26

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.

Theolodus
  • 2,004
  • 1
  • 23
  • 30
  • Any idea why this was necessary? – rstackhouse Mar 29 '15 at 15:20
  • Also, how did you figure out what the previous version was. I could only find the current one. `yolk -V google-api-python-client $google-api-python-client 1.4.0` – rstackhouse Mar 29 '15 at 15:22
  • I'm not really sure why this was necessary. I essentially figured it out by trial and error, knowing that up until I upgraded the client my code was working. My guess is some change in six that hasn't been reflected in oauth2, but I can't really be any more specific than that and I lack the python skill to really probe it further. – Theolodus Mar 30 '15 at 09:37
  • 1
    Downgrading works because the 1.3.2 client version is made to use the 1.4.1 version of six (built into osx). The 1.4.0 client however requires the 1.6.1 version of six, but that is inaccessible because the default osx installation shields this newer installation with the 1.6.1 version. See my post below for a fix. – Andrew Apr 09 '15 at 04:14
  • it did not help in my case, situation unchanged afterwards, same error. – Jeremy Tammik Aug 18 '15 at 19:51
15

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')
Andrew
  • 3,901
  • 15
  • 50
  • 64
  • 7
    Or better yet, just fix your `~/.bash_profile` to export that permanently: `export PYTHONPATH=/Library/Python/2.7/site-packages` – jwadsack Jun 25 '15 at 16:36
  • Included the PYTHONPATH-based solution in the quickstart in a troubleshooting section: https://developers.google.com/gmail/api/quickstart/python#troubleshooting – Eric Koleda Sep 14 '15 at 21:35
  • Worked. Is there any way to fix this with using a virtual environment? – Keith Holliday Mar 13 '16 at 20:01
  • importing sys path in quickstart.py helped.import sys sys.path.insert(1, '/Library/Python/2.7/site-packages') – Amit Singh Sep 18 '16 at 10:41