appengine python remote_api module object has no attribute GoogleCredentials
Question: AttributeError: 'module' object has no attribute 'GoogleCredentials'

I have an appengine app which is running on localhost. I have some tests which
i run and i want to use the remote_api to check the db values. When i try to
access the remote_api by visiting:

    
    
    'http://127.0.0.1:8080/_ah/remote_api' 
    

i get a:

    
    
    "This request did not contain a necessary header" 
    

but its working in the browser.

When i now try to call the remote_api from my tests by calling

    
    
    remote_api_stub.ConfigureRemoteApiForOAuth('localhost:35887','/_ah/remote_api')
    

i get the error:

    
    
    Error
    Traceback (most recent call last):
      File "/home/dan/src/gtup/test/test_users.py", line 38, in test_crud
        remote_api_stub.ConfigureRemoteApiForOAuth('localhost:35887','/_ah/remote_api')
      File "/home/dan/Programs/google-cloud-sdk/platform/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 747, in ConfigureRemoteApiForOAuth
        credentials = client.GoogleCredentials.get_application_default()
    AttributeError: 'module' object has no attribute 'GoogleCredentials'
    

I did try to reinstall the whole google cloud but this didn't work.

When i open the client.py

    
    
    google-cloud-sdk/platform/google_appengine/lib/google-api-python-client/oauth2client/client.py 
    

which is used by remote_api_stub.py, i can see, that there is no
GoogleCredentials class inside of it.

The GoogleCredentials class exists, but inside of other client.py files which
lie at:

    
    
    google-cloud-sdk/platform/google_appengine/lib/oauth2client/oauth2client/client.py
    google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/client.py
    google-cloud-sdk/platform/bq/third_party/oauth2client/client.py
    google-cloud-sdk/lib/third_party/oauth2client/client.py
    

my app.yaml looks like this:

    
    
    application: myapp
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: true
    
    libraries:
    - name: webapp2
      version: latest
    
    builtins:
    - remote_api: on
    
    handlers:
    - url: /.*
      script: main.app
    

Is this just a wrong import/bug inside of appengine. Or am i doing something
wrong to use the remote_api inside of my unittests?


Answer: Answering instead of commenting as I cannot post a comment with my reputation
-

Similar things have happened to me, when running these types of scripts on
mac. Sometimes, your PATH variable gets confused as to which files to actually
check for functions, especially when you have gcloud installed alongside the
app engine launcher. If on mac, I would suggest editing/opening your
~/.bash_profile file to fix this (or possible ~/.bashrc, if on linux). For
example, on my Mac I have the following lines to fix my PATH variable:

    
    
    export PATH="/usr/local/bin:$PATH"
    export PYTHONPATH="/usr/local/google_appengine:$PYTHONPATH
    

These basically make sure the python / command line will look in
/usr/local/bin (or /usr/local/google_appengine in the case of the PYTHONPATH
line) BEFORE anything in the PATH (or PYTHONPATH).

The PATH variable is where the command line checks for python files when you
type them into the prompt. The PYTHONPATH is where your python files find the
modules to load at runtime.

