question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fail to import ServiceAccountCredentials within GAE endpoint tool

See original GitHub issue

I am generating some GAE endpoints library. When running endpoints tool(endpointscfg.py get_client_lib ... ), gcloud import fails. Third party libraries are bundled with GAE project, and oauth2client-2.0.1 is actually exists in library directory.

Affecting versions: 0.10 and above

Traceback (most recent call last):
  File "/usr/local/bin/endpointscfg.py", line 133, in <module>
    run_file(__file__, globals())
  File "/usr/local/bin/endpointscfg.py", line 129, in run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/endpointscfg.py", line 561, in <module>
    main(sys.argv)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/endpointscfg.py", line 557, in main
    args.callback(args)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/endpointscfg.py", line 426, in _GetClientLibCallback
    hostname=args.hostname, application_path=args.application)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/endpointscfg.py", line 388, in _GetClientLib
    application_path=application_path)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/endpointscfg.py", line 187, in GenApiConfig
    module = __import__(module_name, fromlist=base_service_class_name)
  File "/Users/kang/jackend/main.py", line 10, in <module>
    from auth.services import JackEndAuthAPI
  File "/Users/kang/jackend/auth/services.py", line 12, in <module>
    from . import (
  File "/Users/kang/jackend/auth/storage.py", line 9, in <module>
    from ext import cloudstorage as storage
  File "/Users/kang/jackend/ext/cloudstorage.py", line 9, in <module>
    from gcloud import (
  File "/Users/kang/jackend/lib/gcloud/storage/__init__.py", line 45, in <module>
    from gcloud.storage.client import Client
  File "/Users/kang/jackend/lib/gcloud/storage/client.py", line 19, in <module>
    from gcloud.client import JSONClient
  File "/Users/kang/jackend/lib/gcloud/client.py", line 17, in <module>
    from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name ServiceAccountCredentials

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
ghostcommented, Apr 14, 2016

My appengine_config.py looks like this now:

"""
`appengine_config.py` is automatically loaded when Google App Engine
starts a new instance of your application. This runs before any
WSGI applications specified in app.yaml are loaded.
"""

import sys
from google.appengine.ext import vendor

# Third-party libraries are stored in "lib", vendoring will make
# sure that they are importable by the application.
vendor.add('lib')

def unload_module(module_name):
    target_modules = [m for m in sys.modules if m.startswith(module_name)]
    for m in target_modules:
        if m in sys.modules:
            del sys.modules[m]

unload_module('oauth2client')
unload_module('pyasn1_modules')

This workaround would be useful for swapping GAE provided libraries.

3reactions
theacodescommented, Apr 14, 2016

Great.

The long and short is that app engine is barrels of fun when it comes to user-provided newer versions of bundled libraries.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: cannot import name 'ServiceAccountCredentials ...
First, the class you are trying to import is called ServiceAccountCredentials , not ServiceAccountCredential . So try this instead: from ...
Read more >
Authentication between services - Google Cloud
Create a service account and key for the calling service to use. Add support for authentication in the OpenAPI document for your Cloud...
Read more >
Source code for oauth2client.client - Read the Docs
Tools for interacting with OAuth 2.0 protected resources. """ import collections import copy import datetime import json import logging import os import ......
Read more >
oauth2client Documentation - Read the Docs
create_scoped(scopes) method needs to be called in order to create a Credentials object for API calls. classmethod from_json(json_data).
Read more >
client.py - Google Git
Tools for interacting with OAuth 2.0 protected resources. ... import collections ... """Attempts to get implicit credentials in Google App Engine env.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found