Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

The library is asking credentials for running against emulator #327

Description

@karakanb

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.0command: gcloud beta emulators pubsub start --host-port=0.0.0.0:8085ports:
- "8085:8085"restart: unless-stoppedpublisher:
image: python:3.9.2command: sh -c "pip install google-cloud-pubsub~=2.2.0 && python /app/publish.py"volumes:
- .:/appenvironment:
- PUBSUB_EMULATOR_HOST=pubsub:8085
- PUBSUB_PROJECT_ID=test-project

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

fromgoogle.cloudimportpubsub_v1project_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: pubsubIssues related to the googleapis/python-pubsub API.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions