2

I'm trying to run a python flask based application on google app engine using cloud datastore. I'm following the bookshelf example - https://cloud.google.com/python/getting-started/using-cloud-datastore

Everything seems to work in local machine but on app engine, I'm getting ImportError: No module named pwd, which is being imported by oauth2client library.

Is there anything I'm missing. Any help will be appreciated.

The question referenced as duplicate is different. The application there seems to fail only locally, whereas for me everything works locally but fails to work in GAE.

Here's the stack trace (partial) -

...
1384/v1.394932573930853146/application/home/model.py", line 16, in save_user
    ds = get_client()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/application/home/model.py", line 7, in get_client
    return datastore.Client('bookshelf-1384')#current_app.config['PROJECT_ID'])
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/gcloud/datastore/client.py", line 173, in __init__
    super(Client, self).__init__(credentials, http)
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/gcloud/client.py", line 122, in __init__
    credentials = get_credentials()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/gcloud/credentials.py", line 82, in get_credentials
    return client.GoogleCredentials.get_application_default()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/oauth2client/client.py", line 1288, in get_application_default
    return GoogleCredentials._get_implicit_credentials()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/oauth2client/client.py", line 1273, in _get_implicit_credentials
    credentials = checker()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/oauth2client/client.py", line 1226, in _implicit_credentials_from_files
    credentials_filename = _get_well_known_file()
  File "/base/data/home/apps/s~bookshelf-1384/v1.394932573930853146/lib/oauth2client/client.py", line 1392, in _get_well_known_file
    default_config_dir = os.path.join(os.path.expanduser('~'),
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/posixpath.py", line 268, in expanduser
    import pwd
ImportError: No module named pwd
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
user1010373
  • 289
  • 1
  • 5
  • 12
  • What is your `app.yaml` file? – hjpotter92 Aug 15 '16 at 06:07
  • runtime: python27 api_version: 1 threadsafe: yes # Handlers define how to route requests to your application. handlers: - url: .* # This regex directs all routes to main.app script: main.app ` – user1010373 Aug 15 '16 at 14:39
  • This question shouldn't have been marked duplicate... The error is caused by https://github.com/google/oauth2client/issues/578 It will be fixed in a couple of weeks with a new AppEngine SDK. In the meantime you can downgrade the version of the auth2client library in app.yaml. – Max Aug 18 '16 at 08:37
  • @Max, agreed, so I removed the duplicate flag. – Alex Martelli Aug 18 '16 at 16:55
  • To what version do you need to downgrade auth2client in app.yaml for this error to ve avoided? – Praxiteles Jun 03 '17 at 05:45
  • Was this ever actually fixed? We are still getting an ImportError: No module named pwd – Praxiteles Jan 28 '18 at 03:30

2 Answers2

1

The error is caused by http://github.com/google/oauth2client/issues/578.

It will be fixed in a couple of weeks with a new AppEngine SDK. In the meantime you can downgrade the version of the oauth2client library in your app.yaml file.

Max
  • 101
  • 1
  • 3
  • 1
    I can see the latest version as 3.0.0 from https://pypi.python.org/pypi/oauth2client, so I added `- name: oauth2client\n version: 2.0` under `libraries:` in my app.yaml and it still doesn't work. What am I doing wrong? – Afzal S.H. Sep 21 '16 at 10:10
-1

I had this same issue which is a known issue with the SDK. I tried the other solutions suggested on SO (see Google App Engine 'No module named pwd') but it didn't work. I found a work around by installing an older version of oauth2client-2.0.0 overwriting the oauth2client-4.0.0 that came with the pubsub pip install. Try running pip install -t ./lib/ --upgrade --force-reinstall oauth2client==2.0.0 in the project directory and rerunning.

Community
  • 1
  • 1
Paul Bendevis
  • 2,381
  • 2
  • 31
  • 42