Google-api-python-client: Undefined error: 'Module_six_moves_urllib_parse' object has no attribute 'urlencode'

Created on 29 May 2015  路  12Comments  路  Source: googleapis/google-api-python-client

I tried code sample from https://cloud.google.com/bigquery/authorization, with the environment mentioned below and i got the error.

Environment:
python version 2.7.6
google-api-python-client version 1.4.0
six version 1.4.1

However when i downgraded google-api-python-client to 1.3.2 it works

will not fix question

Most helpful comment

The cause of the problem, and the workaround is best explained here: http://stackoverflow.com/a/29666702/702875

The Google APIs Python client library depends on another library called six, which comes pre-installed with Max OSX. The client library needs a newer version however, and although pip installs it Python ends up loading the older version first, leading to the error.

The workaround is to set the system environment variable PYTHONPATH to point directly to pip's install directory, so that the latest version of the six module loads first.

export PYTHONPATH=/Library/Python/2.7/site-packages

You'll need to add that line to you ~/.bashrc file to ensure it's set for each terminal window.

All 12 comments

Hi gozali,

Have you found a fix for this for version 1.4.1 ? I got the same issue as well.

Cheers,
Pepe

not yet @pepedocs, downgraded my api client to 1.3.2 since then

Also reproduced on latest google-api-python-client - downgrade to 1.3.2 resolved this issue.

The cause of the problem, and the workaround is best explained here: http://stackoverflow.com/a/29666702/702875

The Google APIs Python client library depends on another library called six, which comes pre-installed with Max OSX. The client library needs a newer version however, and although pip installs it Python ends up loading the older version first, leading to the error.

The workaround is to set the system environment variable PYTHONPATH to point directly to pip's install directory, so that the latest version of the six module loads first.

export PYTHONPATH=/Library/Python/2.7/site-packages

You'll need to add that line to you ~/.bashrc file to ensure it's set for each terminal window.

Adding export PYTHONPATH=/Library/Python/2.7/site-packages worked for me.

What can I try if adding didn't help?

This is likely due to an outdated version of six on your system. This can happen with OS X system Python because the Apple-provided six library can't be upgraded.

Have you tried using a virtualenv?

Hi there, I added the PYTHONPATH to bashrc but didn't work. Any idea why?

@ohlaylaohoh I really don't recommend using the PYTHONPATH thing. Please use virtualenv.

Use python3 (3.5) and install google-api-python-client-py3 works for me (also need to change these in tools.py of the library

    s.wfile.write("<html><head><title>Authentication Status</title></head>")
    s.wfile.write("<body><p>The authentication flow has completed.</p>")
    s.wfile.write("</body></html>")

to

    s.wfile.write(b"<html><head><title>Authentication Status</title></head>")
    s.wfile.write(b"<body><p>The authentication flow has completed.</p>")
    s.wfile.write(b"</body></html>")

Triaging.

The correct answer is, if you see this symptom, to use a virtualenv rather than the "system" Python,.
The system Python on some platforms (e.g. MacOS) is populated with packages that are used for system operation, and which may not be compatible with the requirements of the api client.

I'm going to close this, as there are two solutions named above (and the PYTHONPATH one is even in the official docs), however, if you need more help, please comment, and I'll try to provide it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings