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

Datastore on GCE - Intermittent Unauthorized 401 #3382

Closed
jmgirven opened this issue May 8, 2017 · 3 comments
Closed

Datastore on GCE - Intermittent Unauthorized 401 #3382

jmgirven opened this issue May 8, 2017 · 3 comments
Assignees
Labels
auth type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jmgirven
Copy link

jmgirven commented May 8, 2017

There are a few questions similar to this, but I don't think any are the same. I apologise if I didn't recognise it.

I am using Datastore inside a docker on a Google Compute Engine instance. The docker container is based off of python:3.4-slim. The python version is Python 3.4.6. I have used pip to install google-cloud-datastore==1.0.0. My GCE instance explicitly has Cloud API access scope Cloud Datastore enabled. I have a worker that regularly (10s interval) checks my datastore for new tasks to process. This makes a query like:

    query = ds_client.query(kind=RepeatingJob.KIND)
    query.add_filter("deleted", "=", False)
    query.add_filter("next_process", "<", datetime.now())
    jobs = list(query.fetch(limit=1))

where ds_client is initialised once in the application:

from google.cloud import datastore
ds_client = datastore.Client()

If I understand correctly, because this is GCE instance and I have enabled the datastore scope, I should not have to do anything more for authorization.

This system works fine for tens of minutes at a time (40 minutes 21 seconds) in my last test. Then an error is raised:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/google/gax/retry.py", line 120, in inner
    return to_call(*args)
  File "/usr/local/lib/python3.4/site-packages/google/gax/retry.py", line 68, in inner
    return a_func(*updated_args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/grpc/_channel.py", line 507, in __call__
    return _end_unary_response_blocking(state, call, False, deadline)
  File "/usr/local/lib/python3.4/site-packages/grpc/_channel.py", line 455, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAUTHENTICATED, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 74, in _catch_remap_gax_error
    yield
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 134, in run_query
    return super(GAPICDatastoreAPI, self).run_query(*args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line 258, in run_query
    return self._run_query(request, options)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 419, in inner
    return api_caller(api_call, this_settings, request)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 407, in base_caller
    return api_call(*args)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 368, in inner
    return a_func(*args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/google/gax/retry.py", line 126, in inner
    ' classified as transient', exception)
google.gax.errors.RetryError: GaxError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.UNAUTHENTICATED, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.)>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/application/jobs/models/repeating_job.py", line 199, in needs_processing
    jobs = list(query.fetch(limit=1))
  File "/usr/local/lib/python3.4/site-packages/google/cloud/iterator.py", line 218, in _items_iter
    for page in self._page_iter(increment=False):
  File "/usr/local/lib/python3.4/site-packages/google/cloud/iterator.py", line 247, in _page_iter
    page = self._next_page()
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/query.py", line 497, in _next_page
    query=query_pb,
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 134, in run_query
    return super(GAPICDatastoreAPI, self).run_query(*args, **kwargs)
  File "/usr/local/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 82, in _catch_remap_gax_error
    six.reraise(error_class, new_exc, sys.exc_info()[2])
  File "/usr/local/lib/python3.4/site-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 74, in _catch_remap_gax_error
    yield
  File "/usr/local/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line 134, in run_query
    return super(GAPICDatastoreAPI, self).run_query(*args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line 258, in run_query
    return self._run_query(request, options)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 419, in inner
    return api_caller(api_call, this_settings, request)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 407, in base_caller
    return api_call(*args)
  File "/usr/local/lib/python3.4/site-packages/google/gax/api_callable.py", line 368, in inner
    return a_func(*args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/google/gax/retry.py", line 126, in inner
    ' classified as transient', exception)
google.cloud.exceptions.Unauthorized: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

At this point, if I immediately retry the request, it fails with the same error. At some point a short (maybe 1 minute) period of time later, the same command starts working again.

I also use Sentry error reporting to track issues. Perhaps interestingly, I noticed that in the tracked variables at this point (/usr/local/lib/python3.4/site-packages/google/gax/retry.py in inner at line 126) that env = RetryError('Retry total timeout exceeded before anyresponse was received',). I don't think I can share that report, but if it is relevant, let me know and I will see what I can do.

@jmgirven
Copy link
Author

jmgirven commented May 8, 2017

$ pip freeze
appdirs==1.4.3
blinker==1.4
cachetools==2.0.0
click==6.7
contextlib2==0.5.5
dill==0.2.6
enum34==1.1.6
Flask==0.12.1
future==0.16.0
gapic-google-cloud-datastore-v1==0.15.3
google-auth==1.0.0
google-auth-httplib2==0.0.2
google-cloud-core==0.24.0
google-cloud-datastore==1.0.0
google-gax==0.15.8
googleapis-common-protos==1.5.2
grpcio==1.2.1
gunicorn==19.7.1
honcho==1.0.1
httplib2==0.10.3
instagram-private-api==1.2.5
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
oauth2client==3.0.0
packaging==16.8
ply==3.8
proto-google-cloud-datastore-v1==0.90.3
protobuf==3.2.0
pyasn1==0.2.3
pyasn1-modules==0.0.8
pyparsing==2.2.0
raven==6.0.0
requests==2.13.0
rsa==3.4.2
simpleflake==0.1.5
six==1.10.0
Werkzeug==0.12.1

@jmgirven
Copy link
Author

jmgirven commented May 8, 2017

Error stops occurring after 5 minutes of failures. Re-occurs after 55-60 minutes of success. (3 tests)

@theacodes theacodes added the auth label May 8, 2017
@theacodes theacodes self-assigned this May 8, 2017
@theacodes theacodes added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label May 8, 2017
@theacodes
Copy link
Contributor

This should be fixed by https://github.com/GoogleCloudPlatform/google-auth-library-python/releases/tag/v1.0.1 which was just released. Try making sure that package is up-to-date and if this is still an issue, let us know.

parthea pushed a commit that referenced this issue Jun 4, 2023
parthea pushed a commit that referenced this issue Jun 4, 2023
* Add samples for Data Catalog lookup_entry [(#2148)](GoogleCloudPlatform/python-docs-samples#2148)

* Add samples for Data Catalog lookup_entry

* Add tests for Data Catalog lookup_entry

* Add samples for lookup_entry by SQL Resource

* Add README.rst

* Improve command line interface

* Removed the "lookup-" prefix from commands
* Handle the --sql-resource optional argument by subparsers

* Refer to GCP public assets in tests

* Add region tags to support Data Catalog docs [(#2169)](GoogleCloudPlatform/python-docs-samples#2169)

* Adds updates including compute [(#2436)](GoogleCloudPlatform/python-docs-samples#2436)

* Adds updates including compute

* Python 2 compat pytest

* Fixing weird \r\n issue from GH merge

* Put asset tests back in

* Re-add pod operator test

* Hack parameter for k8s pod operator

* Auto-update dependencies. [(#2005)](GoogleCloudPlatform/python-docs-samples#2005)

* Auto-update dependencies.

* Revert update of appengine/flexible/datastore.

* revert update of appengine/flexible/scipy

* revert update of bigquery/bqml

* revert update of bigquery/cloud-client

* revert update of bigquery/datalab-migration

* revert update of bigtable/quickstart

* revert update of compute/api

* revert update of container_registry/container_analysis

* revert update of dataflow/run_template

* revert update of datastore/cloud-ndb

* revert update of dialogflow/cloud-client

* revert update of dlp

* revert update of functions/imagemagick

* revert update of functions/ocr/app

* revert update of healthcare/api-client/fhir

* revert update of iam/api-client

* revert update of iot/api-client/gcs_file_to_device

* revert update of iot/api-client/mqtt_example

* revert update of language/automl

* revert update of run/image-processing

* revert update of vision/automl

* revert update testing/requirements.txt

* revert update of vision/cloud-client/detect

* revert update of vision/cloud-client/product_search

* revert update of jobs/v2/api_client

* revert update of jobs/v3/api_client

* revert update of opencensus

* revert update of translate/cloud-client

* revert update to speech/cloud-client

Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
Co-authored-by: Doug Mahugh <dmahugh@gmail.com>

* chore(deps): update dependency google-cloud-datacatalog to v0.6.0 [(#3069)](GoogleCloudPlatform/python-docs-samples#3069)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [google-cloud-datacatalog](https://togithub.com/googleapis/python-datacatalog) | minor | `==0.5.0` -> `==0.6.0` |

---

### Release Notes

<details>
<summary>googleapis/python-datacatalog</summary>

### [`v0.6.0`](https://togithub.com/googleapis/python-datacatalog/blob/master/CHANGELOG.md#&#8203;060httpswwwgithubcomgoogleapispython-datacatalogcomparev050v060-2020-02-24)

[Compare Source](https://togithub.com/googleapis/python-datacatalog/compare/v0.5.0...v0.6.0)

##### Features

-   **datacatalog:** add sample for create a fileset entry quickstart ([#&#8203;9977](https://www.github.com/googleapis/python-datacatalog/issues/9977)) ([16eaf4b](https://www.github.com/googleapis/python-datacatalog/commit/16eaf4b16cdc0ce7361afb1d8dac666cea2a9db0))
-   **datacatalog:** undeprecate resource name helper methods, bump copyright year to 2020, tweak docstring formatting (via synth) ([#&#8203;10228](https://www.github.com/googleapis/python-datacatalog/issues/10228)) ([84e5e7c](https://www.github.com/googleapis/python-datacatalog/commit/84e5e7c340fa189ce4cffca4fdee82cc7ded9f70))
-   add `list_entry_groups`, `list_entries`, `update_entry_group` methods to v1beta1 (via synth) ([#&#8203;6](https://www.github.com/googleapis/python-datacatalog/issues/6)) ([b51902e](https://www.github.com/googleapis/python-datacatalog/commit/b51902e26d590f52c9412756a178265850b7d516))

##### Bug Fixes

-   **datacatalog:** deprecate resource name helper methods (via synth) ([#&#8203;9831](https://www.github.com/googleapis/python-datacatalog/issues/9831)) ([22db3f0](https://www.github.com/googleapis/python-datacatalog/commit/22db3f0683b8aca544cd96c0063dcc8157ad7335))

</details>

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples).

* Simplify noxfile setup. [(#2806)](GoogleCloudPlatform/python-docs-samples#2806)

* chore(deps): update dependency requests to v2.23.0

* Simplify noxfile and add version control.

* Configure appengine/standard to only test Python 2.7.

* Update Kokokro configs to match noxfile.

* Add requirements-test to each folder.

* Remove Py2 versions from everything execept appengine/standard.

* Remove conftest.py.

* Remove appengine/standard/conftest.py

* Remove 'no-sucess-flaky-report' from pytest.ini.

* Add GAE SDK back to appengine/standard tests.

* Fix typo.

* Roll pytest to python 2 version.

* Add a bunch of testing requirements.

* Remove typo.

* Add appengine lib directory back in.

* Add some additional requirements.

* Fix issue with flake8 args.

* Even more requirements.

* Readd appengine conftest.py.

* Add a few more requirements.

* Even more Appengine requirements.

* Add webtest for appengine/standard/mailgun.

* Add some additional requirements.

* Add workaround for issue with mailjet-rest.

* Add responses for appengine/standard/mailjet.

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency google-cloud-datacatalog to v0.7.0 [(#3320)](GoogleCloudPlatform/python-docs-samples#3320)

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>

* Update Data Catalog samples to V1 [(#3382)](GoogleCloudPlatform/python-docs-samples#3382)

Co-authored-by: Takashi Matsuo <tmatsuo@google.com>

* chore(deps): update dependency google-cloud-datacatalog to v0.8.0 [(#3850)](GoogleCloudPlatform/python-docs-samples#3850)

* Update dependency google-cloud-datacatalog to v1 [(#4115)](GoogleCloudPlatform/python-docs-samples#4115)

* chore(deps): update dependency pytest to v5.4.3 [(#4279)](GoogleCloudPlatform/python-docs-samples#4279)

* chore(deps): update dependency pytest to v5.4.3

* specify pytest for python 2 in appengine

Co-authored-by: Leah Cole <coleleah@google.com>

* Update dependency pytest to v6 [(#4390)](GoogleCloudPlatform/python-docs-samples#4390)

* chore: update templates

* chore: update templates

* feat: Migrate to use Microgenerator

* feat: Migrate to use Microgenerator

* feat: Migrate to use Microgenerator

* Migrate API to microgenerator

* Migrate API to microgenerator

* Samples tests

* fix samples tests

* fix lint errors and test coverage metrics

* docs update

* fix docs

* fix docs

* fix docs

* remove .python-version file

Co-authored-by: Ricardo Mendes <50331050+ricardosm-cit@users.noreply.github.com>
Co-authored-by: Gus Class <gguuss@gmail.com>
Co-authored-by: DPEBot <dpebot@google.com>
Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
Co-authored-by: Doug Mahugh <dmahugh@gmail.com>
Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Co-authored-by: Marcelo Costa <mycelo19@gmail.com>
Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
Co-authored-by: Leah Cole <coleleah@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants