Google-cloud-python: "Project was not passed" error, even though ran

Created on 12 May 2016  路  6Comments  路  Source: googleapis/google-cloud-python

I attempted to follow the setup instructions and ran into an odd error. The instructions I was following are here: https://googlecloudplatform.github.io/gcloud-python/stable/gcloud-auth.html

Here is what I attempted:

  1. virtualenv ~/venv
  2. source ~/venv/bin/activate
  3. pip install gcloud
  4. gcloud auth login
  5. python
>>> from gcloud import pubsub
>>> pubsub.Client()

Here's the error I received when I ran pubsub.Client()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../venv/local/lib/python2.7/site-packages/gcloud/client.py", line 184, in __init__
    _ClientProjectMixin.__init__(self, project=project)
  File ".../venv/local/lib/python2.7/site-packages/gcloud/client.py", line 143, in __init__
    raise EnvironmentError('Project was not passed and could not be '
EnvironmentError: Project was not passed and could not be determined from the environment.

I do appear to have valid credentials. gcloud.credentials.get_credentials() happily provides me with a perfectly good GoogleCredentials object which works fine with httplib2 if I invoke it directly.

bigquery

Most helpful comment

Thanks for the report! In addition to credentials, we need to know what project to use: a given set of credentials can have access to multiple projects. On GCE / GAE, we can determine the project from the host setup. On your own machine, you need to set an environment variable. E.g.:

$ export GCLOUD_PROJECT=flaky-piecrust-227

Or you can pass the project to the Client constructor:

>>> from gcloud import pubsub
>>> client = pubsub.Client('flaky-piecrust-227')

I think the "usage doc" sections should all link to a shared page explaining this requirement (similar to the Authentication page). @dhermes, @jgeewax WDYT?

All 6 comments

Thanks for the report! In addition to credentials, we need to know what project to use: a given set of credentials can have access to multiple projects. On GCE / GAE, we can determine the project from the host setup. On your own machine, you need to set an environment variable. E.g.:

$ export GCLOUD_PROJECT=flaky-piecrust-227

Or you can pass the project to the Client constructor:

>>> from gcloud import pubsub
>>> client = pubsub.Client('flaky-piecrust-227')

I think the "usage doc" sections should all link to a shared page explaining this requirement (similar to the Authentication page). @dhermes, @jgeewax WDYT?

Yea, we should probably clarify that... gcloud auth login does handle the auth, but you then need to do $ gcloud config set project <your project ID>, right?

So I ran into this when I started and I was wondering why the project ID isn't picked up from the credentials file?

{
  "type": "service_account",
  "project_id": "<PROJECT_ID>",  <----
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": ""
}

We recommend that you use separate credentials for different projects, so I would think it would be ok to pull it from there with the option to override it later if need be.

you may want to use two separate accounts to simultaneously access data from different projects

https://googlecloudplatform.github.io/gcloud-python/stable/gcloud-auth.html#explicit-credentials

Good call @daspecster, it's never occurred to us.

@dhermes, Is this something that should happen when oauth2client pulls in the other properties from the JSON?

https://github.com/google/oauth2client/blob/ef33f70abb43da50793f169ad7efdd4c72df4966/oauth2client/client.py#L543

Not really. oauth2client is only concerned with auth.

Was this page helpful?
0 / 5 - 0 ratings