Skip to content

ModuleNotFoundError: No module named 'google.appengine' #817

@alirezastack

Description

@alirezastack

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'])

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

  3. 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

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions