Google-api-python-client: ModuleNotFoundError: No module named 'google.appengine'

Created on 29 Jan 2020  路  7Comments  路  Source: googleapis/google-api-python-client

Please run down the following list and make sure you've tried the usual "quick fixes":

Environment details

  • OS: Mac 10.13
  • Python version: 3.7
  • pip version: 19.3.1
  • google-api-python-client version: 1.7.11

Steps to reproduce

  1. Initiate flow with a valid code from oauth2:
            flow = Flow.from_client_secrets_file(
            client_secrets_file=ga['client_secret'],
            scopes=ga['scopes'].split(','),
            redirect_uri=ga['redirect_uri'])
  1. Now when token based on the given code:
    flow.fetch_token(code=request.args['code'])

    1. Now when you issue flow.credentials.to_json() you can see the obtained token.

    2. Now build a service for analytics:

service = build(serviceName='analytics',
                          version='v3',
                          credentials=flow.credentials)

It gives the error below:

2020-01-29 15:12:44,190 [googleapiclient.discovery_cache] file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect
    from google.appengine.api import memcache
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'google.appengine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module>
    from oauth2client.contrib.locked_file import LockedFile
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'oauth2client.contrib.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
    from oauth2client.locked_file import LockedFile
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'oauth2client.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
    from . import file_cache
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
    'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.7/site-packages/Flask_Cors-3.0.8-py3.7.egg/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/Flask_Cors-3.0.8-py3.7.egg/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/Flask_DebugToolbar-0.10.1-py3.7.egg/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/Flask_Classful-0.14.2-py3.7.egg/flask_classful.py", line 268, in proxy
    response = view(**request.view_args)
  File "/usr/local/lib/python3.7/site-packages/Flask_Classful-0.14.2-py3.7.egg/flask_classful.py", line 239, in inner
    return fn(*args, **kwargs)
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/tf_api_common-20191026-py3.7.egg/tf_api_common/jwt.py", line 129, in decorator
    return fn(*a, **k)
  File "/Users/fc/PycharmProjects/something/tf_api/views/oauth.py", line 50, in get
    credentials=flow.credentials)
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery.py", line 231, in build
    raise e
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery.py", line 223, in build
    requested_url, discovery_http, cache_discovery, cache, developerKey)
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery.py", line 276, in _retrieve_discovery_doc
    raise HttpError(resp, content, uri=actual_url)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/analytics/v3/rest returned "Forbidden">

I have installed the latest of below packages:

google-auth-oauthlib
google-api-python-client
oauth2client
google-auth
googleapis-common-protos

scopes I gave for getting the code and then token:

https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/tagmanager.readonly
p2 bug

Most helpful comment

@busunkim96, thank you for your reply.
Yes, the API endpoint link works when opened in the browser. I just started debugging and came across that my timeout is actually happening because of the different unrelated bug :man_facepalming: Sorry for that unclarity.

However the previously mentioned ModuleNotFoundError: No module named 'google.appengine' still happens. As a workaround adding cache_discovery=False to build method is helping for now :+1:

All 7 comments

Did we manage to solve it? I m also getting same error. Tried adding
cache_discovery` to `service = build('calendar', 'v3', credentials=creds, cache_discovery=False)
but now it seems to be timing out on
URL being requested: GET https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest

Hi,

To clarify the logs at the top are from a warning (those exceptions are being caught and handled.)

2020-01-29 15:12:44,190 [googleapiclient.discovery_cache] file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect
    from google.appengine.api import memcache
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'google.appengine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module>
    from oauth2client.contrib.locked_file import LockedFile
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'oauth2client.contrib.locked_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fc/PycharmProjects/something/venv/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
    from oauth2client.locked_file import LockedFile
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'oauth2client.locked_file'

During handling of the above exception, another exception occurred:

The real issue seems to be the request to the discovery document. I wouldn't expect a 403 to get to a public document though.

@leikoilja Are you seeing timeouts or 403s?

Can you open the link as below in your broswer ?https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest

Yes, you should be able to open the link in the browser. Are you unable to see the discovery document @haixia1991?

@busunkim96, thank you for your reply.
Yes, the API endpoint link works when opened in the browser. I just started debugging and came across that my timeout is actually happening because of the different unrelated bug :man_facepalming: Sorry for that unclarity.

However the previously mentioned ModuleNotFoundError: No module named 'google.appengine' still happens. As a workaround adding cache_discovery=False to build method is helping for now :+1:

cache_discovery=False, this works for me too.
Thank you leikoilja, you saved my day

yup this solved my problems too

Was this page helpful?
0 / 5 - 0 ratings