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

bigtable.client shouldn't require credentials when it is connected to the emulator #243

Closed
christineoo opened this issue Mar 10, 2021 · 1 comment · Fixed by #246
Closed
Labels
api: bigtable Issues related to the googleapis/python-bigtable API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@christineoo
Copy link

maybe related to:
#184

In the local environment, when the BigTable client is connected to a BigTable Emulator credentials shouldn't be required.

Environment details

  • OS type and version: macOS Big Sur v11.0.1
  • Python version: 3.7.9
  • pip version: 20.1.1
  • google-cloud-bigtable version: 1.7.0

Steps to reproduce

  1. gcloud beta emulators bigtable start
  2. env BIGTABLE_EMULATOR_HOST=localhost:8086 python main.py

Code example

# main.py
import os

from google.cloud import bigtable

PROJECT_ID = 'my-project'
BIGTABLE_INSTANCE = 'emulator'
TABLE_ID = 'my-table'

print(f"bigtable emulator: {os.getenv('BIGTABLE_EMULATOR_HOST')}")

def main(project_id="project-id", instance_id="instance-id",
         table_id="my-table"):
    # Create a Cloud Bigtable client.
    client = bigtable.Client(project=project_id)

    # Connect to an existing Cloud Bigtable instance.
    instance = client.instance(instance_id)

    # Open an existing table.
    table = instance.table(table_id)

    row_key = 'r1'
    row = table.read_row(row_key.encode('utf-8'))

    column_family_id = 'cf1'
    column_id = 'c1'.encode('utf-8')
    value = row.cells[column_family_id][column_id][0].value.decode('utf-8')

    print('Row key: {}\nData: {}'.format(row_key, value))


if __name__ == '__main__':
    main(PROJECT_ID, BIGTABLE_INSTANCE, TABLE_ID)

Stack trace

bigtable emulator: localhost:8086
Traceback (most recent call last):
  File "main.py", line 33, in <module>
    main(PROJECT_ID, BIGTABLE_INSTANCE, TABLE_ID)
  File "main.py", line 14, in main
    client = bigtable.Client(project=project_id)
  File "/Users/xx/Documents/gcloud-playground/bigtable__temp/env/lib/python3.7/site-packages/google/cloud/bigtable/client.py", line 192, in __init__
    client_options=client_options,
  File "/Users/xx/Documents/gcloud-playground/bigtable__temp/env/lib/python3.7/site-packages/google/cloud/client.py", line 278, in __init__
    Client.__init__(self, credentials=credentials, client_options=client_options, _http=_http)
  File "/Users/xx/Documents/gcloud-playground/bigtable__temp/env/lib/python3.7/site-packages/google/cloud/client.py", line 153, in __init__
    credentials, _ = google.auth.default(scopes=scopes)
  File "/Users/xx/Documents/gcloud-playground/bigtable__temp/env/lib/python3.7/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

Please help to look into this issue 🙏 Thanks!

@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/python-bigtable API. label Mar 10, 2021
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 11, 2021
@torin-givemomentum
Copy link

I'm still encountering this error on version 2.3.3. Are you sure this is fixed?

Environment:
OS type and version: Debian GNU/Linux 10 (buster) (WSL2)
Python version: 3.9.6
google-cloud-bigtable version: 2.3.3

Steps to reproduce
Same commands and code as reported by christineoo above.

Stacktrace

bigtable emulator: localhost:8530
Traceback (most recent call last):
  File "/tmp/main.py", line 33, in <module>
    main(PROJECT_ID, BIGTABLE_INSTANCE, TABLE_ID)
  File "/tmp/main.py", line 14, in main
    client = bigtable.Client(project=project_id)
  File "/home/torin/.cache/pypoetry/virtualenvs/momentum-backend-_rXW-4N5-py3.9/lib/python3.9/site-packages/google/cloud/bigtable/client.py", line 184, in __init__
    super(Client, self).__init__(
  File "/home/torin/.cache/pypoetry/virtualenvs/momentum-backend-_rXW-4N5-py3.9/lib/python3.9/site-packages/google/cloud/client.py", line 317, in __init__
    Client.__init__(
  File "/home/torin/.cache/pypoetry/virtualenvs/momentum-backend-_rXW-4N5-py3.9/lib/python3.9/site-packages/google/cloud/client.py", line 176, in __init__
    credentials, _ = google.auth.default(scopes=scopes)
  File "/home/torin/.cache/pypoetry/virtualenvs/momentum-backend-_rXW-4N5-py3.9/lib/python3.9/site-packages/google/auth/_default.py", line 488, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/python-bigtable API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants