Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The library is asking credentials for running against emulator #327

Closed
karakanb opened this issue Mar 13, 2021 · 3 comments
Closed

The library is asking credentials for running against emulator #327

karakanb opened this issue Mar 13, 2021 · 3 comments
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. type: question Request for information or clarification. Not an issue.

Comments

@karakanb
Copy link

Environment details

  • OS type and version: MacOS 11.2.2 (20D80) & Docker 3.2.1
  • Python version: Python 3.9.2
  • pip version: pip 21.0.1
  • google-cloud-pubsub version: 2.2.0

Steps to reproduce

Use the following docker-compose.yml file:

version: "3.7"

services:
  pubsub:
    image: google/cloud-sdk:331.0.0
    command: gcloud beta emulators pubsub start --host-port=0.0.0.0:8085
    ports:
      - "8085:8085"
    restart: unless-stopped

  publisher:
    image: python:3.9.2
    command: sh -c "pip install google-cloud-pubsub~=2.2.0 && python /app/publish.py"
    volumes:
      - .:/app
    environment:
      - PUBSUB_EMULATOR_HOST=pubsub:8085
      - PUBSUB_PROJECT_ID=test-project

and the following content as publish.py in the same directory:

from google.cloud import pubsub_v1

project_id = "test-project"
topic_id = "test-topic"

publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(project_id, topic_id)
publisher.publish(topic_path, b'My first message!')

When I run the file above, the execution fails with the library failing to run against the local emulator with the error:

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

As far as I understand, there should be no credentials involved since the script is running against the emulator, and I'd just expect the request to work as it is.

If I use the 2.1.0 version, the script works just fine. The reason I am running 2.2.0 is because of #325, and since there is no solution to that with 2.4.0 as of today, I needed to downgrade to this version. I am unable to test this due to being unable to run 2.4.0 against the emulator, therefore I wanted to report this in case this is a regression introduced with 2.2.0 that might be there for other versions as well.

Stack trace

$ python publish.py 
Traceback (most recent call last):
  File "/app/publish.py", line 6, in <module>
    publisher = pubsub_v1.PublisherClient()
  File "/usr/local/lib/python3.9/site-packages/google/cloud/pubsub_v1/publisher/client.py", line 141, in __init__
    client_for_mtls_info = publisher_client.PublisherClient(
  File "/usr/local/lib/python3.9/site-packages/google/pubsub_v1/services/publisher/client.py", line 350, in __init__
    self._transport = Transport(
  File "/usr/local/lib/python3.9/site-packages/google/pubsub_v1/services/publisher/transports/grpc.py", line 159, in __init__
    credentials, _ = auth.default(
  File "/usr/local/lib/python3.9/site-packages/google/auth/_default.py", line 483, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Mar 13, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 14, 2021
@plamut
Copy link
Contributor

plamut commented Mar 15, 2021

This might be a duplicate of #249, the issue with credentials has been fixed in v2.3.0 (release notes).

@karakanb Can you try upgrading the library and see if it fixes the problem for you?

@plamut plamut added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Mar 15, 2021
@karakanb
Copy link
Author

As I have mentioned, I cannot upgrade it for now since the v2.3.0 and v2.4.0 have the problem described in #325, so I will wait for future releases, thanks.

@plamut
Copy link
Contributor

plamut commented Mar 15, 2021

Ah, of course, the fix from #297 has not been released yet.

You can use the current development version, if you wish, or indeed wait for the next release, which should happen in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants