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

"grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAUTHENTICATED" after leaving code running for multiple days #3212

Closed
ensonic opened this issue Mar 27, 2017 · 29 comments
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. auth grpc priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@ensonic
Copy link

ensonic commented Mar 27, 2017

Code is running on GKE. The docker image is based on ubuntu:xenial and has Python 3.5.2.
These are the packages:

dill==0.2.6
enum34==1.1.6
future==0.16.0
gapic-google-cloud-pubsub-v1==0.15.3
google-auth==0.8.0
google-auth-httplib2==0.0.2
google-cloud-core==0.23.1
google-cloud-pubsub==0.23.0
google-gax==0.15.8
googleapis-common-protos==1.5.2
grpc-google-iam-v1==0.11.1
grpcio==1.1.3
httplib2==0.10.3
oauth2client==3.0.0
ply==3.8
proto-google-cloud-pubsub-v1==0.15.3
protobuf==3.2.0
pyasn1==0.2.3
pyasn1-modules==0.0.8
retrying==1.3.3
rsa==3.4.2
six==1.10.0

When leaving the code running for several days we get a series of such exceptions:

0327 02:59:26.398870232      14 plugin_credentials.c:70]    Getting metadata from plugin failed with error: Traceback (most recent call last):
  File "src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi", line 154, in grpc._cython.cygrpc.plugin_get_metadata (src/python/grpcio/grpc/_cython/cygrpc.c:6918)
  File "/usr/local/lib/python3.5/dist-packages/grpc/_plugin_wrapping.py", line 106, in __call__
    AuthMetadataPluginCallback(wrapped_cygrpc_callback))
  File "/usr/local/lib/python3.5/dist-packages/google/auth/transport/grpc.py", line 68, in __call__
    callback(self._get_authorization_headers(context), None)
  File "/usr/local/lib/python3.5/dist-packages/google/auth/transport/grpc.py", line 56, in _get_authorization_headers
    headers)
  File "/usr/local/lib/python3.5/dist-packages/google/auth/credentials.py", line 116, in before_request
    self.refresh(request)
  File "/usr/local/lib/python3.5/dist-packages/google/auth/compute_engine/credentials.py", line 88, in refresh
    self._retrieve_info(request)
  File "/usr/local/lib/python3.5/dist-packages/google/auth/compute_engine/credentials.py", line 72, in _retrieve_info
    self._service_account_email = info['email']
KeyError: 'email'

later in the log we get:

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, Traceback (most recent call last):.  File "src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi", line 154, in grpc._cython.cygrpc.plugin_get_metadata (src/python/grpcio/grpc/_cython/cygrpc.c:6918).  File "/usr/local/lib/python3.5/dist-packages/grpc/_plugin_wrapping.py", line 106, in __call__.    AuthMetadataPluginCallback(wrapped_cygrpc_callback)).  File "/usr/local/lib/python3.5/dist-packages/google/auth/transport/grpc.py", line 68, in __call__.    callback(self._get_authorization_headers(context), None).  File "/usr/local/lib/python3.5/dist-packages/google/auth/transport/grpc.py", line 56, in _get_authorization_headers.    headers).  File "/usr/local/lib/python3.5/dist-packages/google/auth/credentials.py", line 116, in before_request.    self.refresh(request).  File "/usr/local/lib/python3.5/dist-packages/google/auth/compute_engine/credentials.py", line 91, in refresh.    service_account=self._service_account_email).  File "/usr/local/lib/python3.5/dist-packages/google/auth/compute_engine/_metadata.py", line 198, in get_service_account_token.    seconds=token_json['expires_in']).KeyError: 'expires_in'.)>)

The code where it starts to fails is a subscription.pull(return_immediately=False, max_messages=10) wrapped into a @retrying.retry(stop_max_attempt_number=5).

A similar looking error was reported in #2684 but this does not seem to be the same issue.

@daspecster daspecster added api: pubsub Issues related to the Pub/Sub API. auth labels Mar 27, 2017
@ensonic
Copy link
Author

ensonic commented Apr 4, 2017

This happened again (from pubsub_client.list_topics()). To make it clear, the auth works; it stops working after some time.
Is the api not supporting long running clients? if there is an upper limit on the life time of a client please document this, as well as tell users how to handle this case.

@lukesneeringer
Copy link
Contributor

Hmm, I am not aware of an upper limit on the lifetime of a client, but that does sound like the error you are getting. We will try to find out.

@lukesneeringer lukesneeringer added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed auth labels Apr 4, 2017
@ccmonnett
Copy link

ccmonnett commented Apr 6, 2017

Seeing the same thing on a script we left running on a standard GCP VM instance (Debian 8.7). Python 2.7.9.

Some of the packages (prototype instance, pip freeze is quite long...):

gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gapic-google-cloud-pubsub-v1==0.15.3
gapic-google-cloud-spanner-admin-database-v1==0.15.3
gapic-google-cloud-spanner-admin-instance-v1==0.15.3
gapic-google-cloud-spanner-v1==0.15.3
gapic-google-cloud-speech-v1beta1==0.15.3
gapic-google-cloud-vision-v1==0.90.3
google-auth==0.10.0
google-auth-httplib2==0.0.2
google-cloud==0.23.0
google-cloud-bigquery==0.23.0
google-cloud-bigtable==0.23.1
google-cloud-core==0.23.1
google-cloud-datastore==0.23.0
google-cloud-dns==0.23.0
google-cloud-error-reporting==0.23.2
google-cloud-language==0.23.1
google-cloud-logging==0.23.1
google-cloud-monitoring==0.23.0
google-cloud-pubsub==0.23.0
google-cloud-resource-manager==0.23.0
google-cloud-runtimeconfig==0.23.0
google-cloud-spanner==0.23.1
google-cloud-speech==0.23.0
google-cloud-storage==0.23.1
google-cloud-translate==0.23.0
google-cloud-vision==0.23.3
google-gax==0.15.8
googleapis-common-protos==1.5.2
grpc-google-iam-v1==0.11.1
grpcio==1.2.1
changes = self.subscription.pull(return_immediately=True, max_messages=1)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/cloud/pubsub/subscription.py", line 332, in pull
    self.full_name, return_immediately, max_messages)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/cloud/pubsub/_gax.py", line 415, in subscription_pull
    return_immediately=return_immediately)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/cloud/gapic/pubsub/v1/subscriber_client.py", line 705, in pull
    return self._pull(request, options)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 419, in inner
    return api_caller(api_call, this_settings, request)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 407, in base_caller
    return api_call(*args)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 368, in inner
    return a_func(*args, **kwargs)
  File "/home/ccmonnett/venv/ner/local/lib/python2.7/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.)>)

It runs great for some time, then we inevitably see this error if it's left running with nohup. Unfortunately I don't have timestamps to tell you roughly how long it takes to see it.

@irri
Copy link

irri commented Apr 7, 2017

Getting the same error here as well. The errors keeps coming for an interval of 5-10 minutes every hour.

This is for a pubsub client that is running for a long time (hours).

Traceback (most recent call last):
  File "/opt/xxx/worker.py", line 183, in start_worker
    processed = receive_message(pubsub_client, gcs_client, xxx.PUBSUB_XXX_TOPIC_NAME, xxx.PUBSUB_XXX_SUBSCRIPTION_NAME)
  File "/opt/xxx/worker.py", line 43, in receive_message
    results = subscription.pull(return_immediately=True, max_messages=1)
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/pubsub/subscription.py", line 332, in pull
    self.full_name, return_immediately, max_messages)
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/pubsub/_gax.py", line 415, in subscription_pull
    return_immediately=return_immediately)
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/gapic/pubsub/v1/subscriber_client.py", line 705, in pull
    return self._pull(request, options)
  File "/usr/local/lib/python3.5/dist-packages/google/gax/api_callable.py", line 419, in inner
    return api_caller(api_call, this_settings, request)
  File "/usr/local/lib/python3.5/dist-packages/google/gax/api_callable.py", line 407, in base_caller
    return api_call(*args)
  File "/usr/local/lib/python3.5/dist-packages/google/gax/api_callable.py", line 368, in inner
    return a_func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-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.)>)

Here's a part of my pip freeze:

gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gapic-google-cloud-pubsub-v1==0.15.3
gapic-google-cloud-spanner-admin-database-v1==0.15.3
gapic-google-cloud-spanner-admin-instance-v1==0.15.3
gapic-google-cloud-spanner-v1==0.15.3
gapic-google-cloud-speech-v1beta1==0.15.3
gapic-google-cloud-vision-v1==0.90.3
google-api-python-client==1.6.2
google-auth==0.10.0
google-auth-httplib2==0.0.2
google-cloud==0.23.0
google-cloud-bigquery==0.23.0
google-cloud-bigtable==0.23.1
google-cloud-core==0.23.1
google-cloud-datastore==0.23.0
google-cloud-dns==0.23.0
google-cloud-error-reporting==0.23.2
google-cloud-language==0.23.1
google-cloud-logging==0.23.1
google-cloud-monitoring==0.23.0
google-cloud-pubsub==0.23.0
google-cloud-resource-manager==0.23.0
google-cloud-runtimeconfig==0.23.0
google-cloud-spanner==0.23.1
google-cloud-speech==0.23.0
google-cloud-storage==0.23.1
google-cloud-translate==0.23.0
google-cloud-vision==0.23.3
google-gax==0.15.8
googleapis-common-protos==1.5.2
grpc-google-iam-v1==0.11.1
grpcio==1.1.0
grpcio-tools==1.1.0
httplib2==0.10.3
matplotlib==2.0.0
networkx==1.11
oauth2client==3.0.0
proto-google-cloud-datastore-v1==0.90.3
proto-google-cloud-error-reporting-v1beta1==0.15.3
proto-google-cloud-logging-v2==0.91.3
proto-google-cloud-pubsub-v1==0.15.3
proto-google-cloud-spanner-admin-database-v1==0.15.3
proto-google-cloud-spanner-admin-instance-v1==0.15.3
proto-google-cloud-spanner-v1==0.15.3
proto-google-cloud-speech-v1beta1==0.15.3
proto-google-cloud-vision-v1==0.90.3
protobuf==3.2.0

@lukesneeringer
Copy link
Contributor

@jonparrott Any ideas of how I can attack this problem?

@theacodes
Copy link
Contributor

@lukesneeringer I'm gonna look into it. It seems that we need to enumerate and validate the failure modes for gRPC streaming when auth fails.

@theacodes
Copy link
Contributor

@ensonic @ccmonnett @irri Can any of you show the complete code that invoking subscription.pull?

@theacodes
Copy link
Contributor

@lukesneeringer I think that gax just needs to retry grpc errors with UNAUTHENTICATED. I'm not sure though.

@irri
Copy link

irri commented Apr 13, 2017

@jonparrott Here's the simplified version of what I'm running:

def create_pubsub_client():
    client = pubsub.Client.from_service_account_json(PATH_TO_KEY, project=PROJECT_NAME)
    return client

def receive_message(pubsub_client, topic_name, subscription_name):
    topic = pubsub_client.topic(topic_name)
    subscription = topic.subscription(subscription_name)

    results = subscription.pull(return_immediately=True, max_messages=1)

    for ack_id, message in results:
        # do stuff

def main():
    pubsub_client = create_pubsub_client()

    while True:
        try:
            receive_message(pubsub_client, PUBSUB_TOPIC_NAME, PUBSUB_SUBSCRIPTION_NAME) 
        except Exception as e:
           # log error
        time.sleep(1)

By moving the creation of the pubsub client into the while loop (and thus re-creating a new one every second) the problems go away. But I feel that is not a beautiful production-ready solution.

@mxmzdlv
Copy link

mxmzdlv commented Apr 13, 2017

I've got the same error message on GAE, but with pushing messages to pubsub. It usually appears every 30 minutes or so. The workaround is to create a new pubsub client before pushing a message. It is not ideal though, because it introduces an additional delay.

@theacodes
Copy link
Contributor

@irri @mxmzdlv @ensonic can any of you try using a new credential type and seeing if this goes away? Make sure you have the latest google-auth and try this:

import google.auth
import google.auth.jwt

credentials, project = google.auth.default()
jwt_credentials = google.auth.jwt.OnDemandCredentials.from_signing_credentials(credentials)
# Alternatively you can use OnDemandCredentials. from_service_account_file()

client = pub.Client(project=project, credentials=jwt_credentials)

@mxmzdlv
Copy link

mxmzdlv commented Apr 15, 2017

@jonparrott I've tried it and I still get the error message, but less frequently – always after 65 minutes and it seems to fix itself on subsequent 1-10 requests (the instance gets ~10 req/s). I've also tried changing token_lifetime – changing it to 5 minutes gives me the error every 10 minutes. It is still way better than using default credential type though, it used to take up to 5 minutes to fix itself:
screen shot 2017-04-15 at 12 31 15 pm

@theacodes
Copy link
Contributor

@lukesneeringer at this point I have no idea. It seems somehow during the credentials refresh the old, expired token can still be used. Additionally, it doesn't appear that authentication errors are being retried appropriately.

@theacodes
Copy link
Contributor

@mxmzdlv thanks for giving that a try. :)

@ghost
Copy link

ghost commented Apr 18, 2017

As another datapoint I can report that i've maxed out a 10k/month sentry.io free account with these errors from datastore.client.get_multi/put_multi and pubsub.subscription.acknowledge (the latter wrapped in RetryError: GaxError....(StatusCode.UNAUTHENTICATED,....) on a 300-500 req/s setup (before get/put_multi and with 100 messages per pubsub.publish)

@theacodes
Copy link
Contributor

@nathanielmanistaatgoogle is it possible we're doing something wrong with grpc authentication? iirc, you reviewed the code in google-auth for this.

@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.

@gylu
Copy link

gylu commented Jun 28, 2017

Does pip install google-cloud-pubsub automatically install the latest google-auth-library-python?

Because I think I bumped into the same issue. I'm using python2.7 and below is what my pip freeze shows:

cachetools==2.0.0
certifi==2017.4.17
chardet==3.0.4
dill==0.2.6
enum34==1.1.6
future==0.16.0
futures==3.1.1
gapic-google-cloud-pubsub-v1==0.15.4
google-auth==1.0.1
google-auth-httplib2==0.0.2
google-cloud-bigquery==0.25.0
google-cloud-core==0.25.0
google-cloud-pubsub==0.26.0
google-gax==0.15.13
googleapis-common-protos==1.5.2
grpc-google-iam-v1==0.11.1
grpcio==1.4.0
httplib2==0.10.3
idna==2.5
influxdb==4.1.1
oauth2client==3.0.0
ply==3.8
proto-google-cloud-pubsub-v1==0.15.4
protobuf==3.3.0
pyasn1==0.2.3
pyasn1-modules==0.0.9
python-dateutil==2.6.0
pytz==2017.2
requests==2.18.1
rsa==3.4.2
six==1.10.0
ujson==1.35
urllib3==1.21.1

@theacodes
Copy link
Contributor

@gylu 1.0.1 is the latest, but can you tell us more about the issue you're experiencing? This particular issue is that after ~60 minutes requests will fail with unauthenticated for ~5 minutes and then will work for ~60 minutes (repeat).

@gylu
Copy link

gylu commented Jun 28, 2017

@jonparrott My error was quite similar. I had it running for about an hour when this occurred (my code just stops, it doesn't try to keep on running, so I don't know about the ~5min-bad then ~60min-good cycle). I will try to rerun it and see if the same thing happens.

Here's what my code is mainly doing. I am reading out of Pubsub and writing into a database.:

def receive_messages(topic_name, subscription_name):
    topic = pubsub_client.topic(topic_name)
    subscription = topic.subscription(subscription_name)
    while True:
        results = subscription.pull(return_immediately=False,max_messages=1000)
        acks=[]
        for ack_id, message in results:
            acks.append(ack_id)
            #store messages in a list and then write to DB
        #write messages to DB
        subscription.acknowledge(acks)

But below is some of the printout I got when it failed:

E0627 20:58:02.207642000 140736566334400 plugin_credentials.c:74]      Getting metadata from plugin failed with error: Traceback (most recent call last):
  File "src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi", line 154, in grpc._cython.cygrpc.plugin_get_metadata (src/python/grpcio/grpc/_cython/cygrpc.c:6838)

...

  File "/Users/xxx/env/lib/python2.7/site-packages/httplib2/__init__.py", line 1355, in _conn_request
    response = conn.getresponse()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1132, in getresponse
    response.begin()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 734, in recv
    return self.read(buflen)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 621, in read
    v = self._sslobj.read(len or 1024)
error: [Errno 54] Connection reset by peer

Traceback (most recent call last):

...
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, Traceback (most recent call last):
  File "src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi", line 154, in grpc._cython.cygrpc.plugin_get_metadata (src/python/grpcio/grpc/_cython/cygrpc.c:6838)

...

  File "/Users/xxx/env/lib/python2.7/site-packages/httplib2/__init__.py", line 1355, in _conn_request
    response = conn.getresponse()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1132, in getresponse
    response.begin()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 734, in recv
    return self.read(buflen)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 621, in read
    v = self._sslobj.read(len or 1024)
error: [Errno 54] Connection reset by peer
)>)

@theacodes
Copy link
Contributor

@gylu can you give me the following output from when you get this error?

import datetime
print(pubsub_client.credentials)
print(pubsub_client.credentials.valid)
print(pubsub_client.credentials.expiry)
print(datetime.datetime.utcnow())

@ppawiggers
Copy link

ppawiggers commented Oct 17, 2017

Same issue here. The code is running fine for a while, but suddenly I get this error:

Exception in thread Consumer helper: consume bidirectional stream:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 248, in _blocking_consume
    self._policy.on_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/policy/thread.py", line 135, in on_exception
    raise exception
  File "/usr/local/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 234, in _blocking_consume
    for response in response_generator:
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 348, in __next__
    return self._next()
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 342, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, OS Error)>

My code:

def handle_pubsub_message(self, message):
    task = message.data.decode('utf-8')
    logger.info(task)

    message.ack()

def handle(self, *args, **options):
    subscriber = pubsub.SubscriberClient()

    subscriber.subscribe(
        settings.PUBSUB_SUBSCRIPTION_WORKER,
        callback=self.handle_pubsub_message
    )

    print('Listening for messages on {}'.format(settings.PUBSUB_SUBSCRIPTION_WORKER))
    while True:
        time.sleep(10)

@tseaver
Copy link
Contributor

tseaver commented Oct 17, 2017

@ppawiggers Note the different error codes: yours is UNAVAILABLE, which indicates a transient back-end failure (should be auto-retried). The error reported by @ensonic is UNAUTHENTICATED, which indicates that the credentials associated with the client expired and were not auto-refreshed.

Your issue seems more like #3888 than this one.

@pankajkumar
Copy link

pankajkumar commented Oct 18, 2017

@jonparrott @tseaver I am also experiencing the same issue while calling google vision APIs

Here is the stacktrace:-

File "/usr/local/lib/python2.7/site-packages/google/cloud/gapic/vision/v1/image_annotator_client.py", line 179, in batch_annotate_images
    return self._batch_annotate_images(request, options)
  File "/usr/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 452, in inner
    return api_caller(api_call, this_settings, request)
  File "/usr/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 438, in base_caller
    return api_call(*args)
  File "/usr/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 376, in inner
    return a_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/google/gax/retry.py", line 127, in inner
    ' classified as transient', exception)
RetryError: RetryError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.UNAUTHENTICATED, Getting metadata from plugin failed with error: Traceback (most recent call last):
  File "src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi", line 138, in grpc._cython.cygrpc.plugin_get_metadata (src/python/grpcio/grpc/_cython/cygrpc.c:7075)
  File "/usr/local/lib/python2.7/site-packages/grpc/_plugin_wrapping.py", line 91, in __call__
    AuthMetadataPluginCallback(wrapped_cygrpc_callback))
  File "/usr/local/lib/python2.7/site-packages/google/auth/transport/grpc.py", line 73, in __call__
    callback(self._get_authorization_headers(context), None)
  File "/usr/local/lib/python2.7/site-packages/google/auth/transport/grpc.py", line 61, in _get_authorization_headers
    headers)
  File "/usr/local/lib/python2.7/site-packages/google/auth/credentials.py", line 121, in before_request
    self.refresh(request)
  File "/usr/local/lib/python2.7/site-packages/google/oauth2/service_account.py", line 322, in refresh
    request, self._token_uri, assertion)
  File "/usr/local/lib/python2.7/site-packages/google/oauth2/_client.py", line 143, in jwt_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "/usr/local/lib/python2.7/site-packages/google/oauth2/_client.py", line 104, in _token_endpoint_request
    method='POST', url=token_uri, headers=headers, body=body)
  File "/usr/local/lib/python2.7/site-packages/google/auth/transport/requests.py", line 115, in __call__
    raise exceptions.TransportError(exc)
TransportError: ("bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)",)

And here is dump of my pip freeze, I am using google-auth version 1.1.1:-

aniso8601==1.3.0
appdirs==1.4.3
asn1crypto==0.22.0
boto3==1.4.4
botocore==1.5.77
cachetools==2.0.1
certifi==2017.4.17
cffi==1.10.0
chardet==3.0.4
click==6.7
conda==4.3.16
cryptography==1.9
dill==0.2.7.1
Django==1.11.1
djangorestframework==3.6.3
docutils==0.13.1
enum34==1.1.6
Flask==0.12.2
Flask-Cors==3.0.3
Flask-RESTful==0.3.6
future==0.16.0
futures==3.1.1
fuzzywuzzy==0.15.1
gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gapic-google-cloud-pubsub-v1==0.15.4
gapic-google-cloud-spanner-admin-database-v1==0.15.3
gapic-google-cloud-spanner-admin-instance-v1==0.15.3
gapic-google-cloud-spanner-v1==0.15.3
google-auth==1.1.1
google-cloud==0.27.0
google-cloud-bigquery==0.26.0
google-cloud-bigtable==0.26.0
google-cloud-core==0.26.0
google-cloud-datastore==1.2.0
google-cloud-dns==0.26.0
google-cloud-error-reporting==0.26.0
google-cloud-language==0.27.0
google-cloud-logging==1.2.0
google-cloud-monitoring==0.26.0
google-cloud-pubsub==0.27.0
google-cloud-resource-manager==0.26.0
google-cloud-runtimeconfig==0.26.0
google-cloud-spanner==0.26.0
google-cloud-speech==0.28.0
google-cloud-storage==1.3.2
google-cloud-translate==1.1.0
google-cloud-videointelligence==0.25.0
google-cloud-vision==0.26.0
google-gax==0.15.15
google-resumable-media==0.2.3
googleapis-common-protos==1.5.3
grpc-google-iam-v1==0.11.4
grpcio==1.6.3
httplib2==0.10.3
idna==2.5
ipaddress==1.0.18
itsdangerous==0.24
Jinja2==2.9.6
jmespath==0.9.3
MarkupSafe==1.0
monotonic==1.3
MultipartPostHandler==0.1.0
numpy==1.13.1
oauth2client==3.0.0
olefile==0.44
opencv-python==3.3.0.10
packaging==16.8
pandas==0.20.3
pdfminer==20140328
Pillow==4.3.0
ply==3.8
proto-google-cloud-datastore-v1==0.90.4
proto-google-cloud-error-reporting-v1beta1==0.15.3
proto-google-cloud-logging-v2==0.91.3
proto-google-cloud-pubsub-v1==0.15.4
proto-google-cloud-spanner-admin-database-v1==0.15.3
proto-google-cloud-spanner-admin-instance-v1==0.15.3
proto-google-cloud-spanner-v1==0.15.3
protobuf==3.4.0
pyasn1==0.3.7
pyasn1-modules==0.1.5
pycosat==0.6.1
pycparser==2.17
pymongo==3.4.0
pyodbc==4.0.17
pyOpenSSL==17.0.0
pyparsing==2.2.0
pysolr==3.6.0
python-dateutil==2.6.0
python-Levenshtein==0.12.0
pytz==2017.2
requests==2.18.1
rsa==3.4.2
ruamel.ordereddict==0.4.13
ruamel.yaml==0.15.34
s3transfer==0.1.10
schedule==0.4.3
six==1.10.0
tenacity==4.4.0
urllib3==1.21.1
virtualenv==15.1.0
watson-developer-cloud==0.26.0
Werkzeug==0.12.2

@FingerLiu
Copy link

same here ...
I am using datastore,
It worked fine for a few days,
but it suddenly down, kept telling me this(without auto repair as above).
Anyone could help me...

{
 insertId:  "nlcmmbg3521ofb"  
 labels: {…}  
 logName:  "projects/starscan-160105/logs/qrpay-seller"  
 receiveTimestamp:  "2017-10-31T08:51:55.433761728Z"  
 resource: {…}  
 severity:  "ERROR"  
 textPayload:  "Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/google/gax/retry.py", line 121, 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 492, in __call__
    return _end_unary_response_blocking(state, call, False, deadline)
  File "/usr/local/lib/python3.4/site-packages/grpc/_channel.py", line 440, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAUTHENTICATED, Deadline Exceeded)>
"  
 timestamp:  "2017-10-31T08:51:54Z"  
}
 
gapic-google-cloud-datastore-v1 (0.15.3)
gapic-google-cloud-error-reporting-v1beta1 (0.15.3)
gapic-google-cloud-logging-v2 (0.91.3)
gapic-google-cloud-pubsub-v1 (0.15.4)
gapic-google-cloud-spanner-admin-database-v1 (0.15.3)
gapic-google-cloud-spanner-admin-instance-v1 (0.15.3)
gapic-google-cloud-spanner-v1 (0.15.3)
gapic-google-cloud-speech-v1beta1 (0.15.3)
gapic-google-cloud-vision-v1 (0.90.3)
google-auth (1.1.1)
google-auth-httplib2 (0.0.2)
google-cloud (0.27.0)
google-cloud-bigquery (0.26.0)
google-cloud-bigtable (0.26.0)
google-cloud-core (0.26.0)
google-cloud-datastore (1.2.0)
google-cloud-dns (0.26.0)
google-cloud-error-reporting (0.26.0)
google-cloud-language (0.27.0)
google-cloud-logging (1.2.0)
google-cloud-monitoring (0.26.0)
google-cloud-pubsub (0.27.0)
google-cloud-resource-manager (0.26.0)
google-cloud-runtimeconfig (0.26.0)
google-cloud-spanner (0.26.0)
google-cloud-speech (0.28.0)
google-cloud-storage (1.3.2)
google-cloud-translate (1.1.0)
google-cloud-videointelligence (0.25.0)
google-cloud-vision (0.26.0)
google-gax (0.15.15)
google-resumable-media (0.3.1)
googleapis-common-protos (1.5.3)
greenlet (0.4.12)
grpc-google-iam-v1 (0.11.4)
grpcio (1.7.0)
gunicorn (19.7.1)
honcho (1.0.1)
httplib2 (0.10.3)
idna (2.5)
ipython (5.4.1)
ipython-genutils (0.2.0)
isort (4.2.15)
itsdangerous (0.24)
Jinja2 (2.9.6)
jmespath (0.9.3)
kombu (4.0.2)
lazy-object-proxy (1.3.1)
line-pay-sdk (0.0.1)
MarkupSafe (1.0)
mccabe (0.6.1)
monotonic (1.4)
oauth2client (4.0.0)
optionaldict (0.1.1)
pbr (3.0.1)
pexpect (4.2.1)
pickleshare (0.7.4)
pip (9.0.1)
ply (3.8)
prompt-toolkit (1.0.15)
proto-google-cloud-datastore-v1 (0.90.4)
proto-google-cloud-error-reporting-v1beta1 (0.15.3)
proto-google-cloud-logging-v2 (0.91.3)
proto-google-cloud-pubsub-v1 (0.15.4)
proto-google-cloud-spanner-admin-database-v1 (0.15.3)
proto-google-cloud-spanner-admin-instance-v1 (0.15.3)
proto-google-cloud-spanner-v1 (0.15.3)
proto-google-cloud-speech-v1beta1 (0.15.3)
proto-google-cloud-vision-v1 (0.90.3)

@FingerLiu
Copy link

FingerLiu commented Nov 1, 2017

Update...
It seems this is due to some update of google-cloud
I freeze my env to older verson solved the problem.
Below works fine now:

asn1crypto==0.23.0
gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gapic-google-cloud-spanner-admin-database-v1==0.15.3
gapic-google-cloud-spanner-admin-instance-v1==0.15.3
gapic-google-cloud-spanner-v1==0.15.3
googleapis-common-protos==1.5.2
google-auth==1.0.2
google-cloud==0.27.0
google-cloud-core==0.26.0
google-cloud-datastore==1.2.0
google-cloud-dns==0.26.0
google-cloud-error-reporting==0.26.0
google-cloud-language==0.27.0
google-cloud-logging==1.2.0
google-cloud-monitoring==0.26.0
google-cloud-resource-manager==0.26.0
google-cloud-runtimeconfig==0.26.0
google-cloud-spanner==0.26.0
google-cloud-storage==1.3.2
google-cloud-translate==1.1.0
google-gax==0.15.14
google-resumable-media==0.2.3
greenlet==0.4.12
grpc-google-iam-v1==0.11.1
grpcio==1.6.0
gunicorn==19.7.1
honcho==1.0.1
httplib2==0.10.3
idna==2.5
ipython-genutils==0.2.0
itsdangerous==0.24
monotonic==1.3
oauth2client==3.0.0
optionaldict==0.1.1
pexpect==4.2.1
pickleshare==0.7.4
ply==3.8
prompt-toolkit==1.0.15
protobuf==3.4.0
proto-google-cloud-datastore-v1==0.90.4
proto-google-cloud-error-reporting-v1beta1==0.15.3
proto-google-cloud-logging-v2==0.91.3
proto-google-cloud-pubsub-v1==0.15.4
proto-google-cloud-spanner-admin-database-v1==0.15.3
proto-google-cloud-spanner-admin-instance-v1==0.15.3
proto-google-cloud-spanner-v1==0.15.3
ptyprocess==0.5.2
pyasn1==0.3.4
pyasn1-modules==0.1.4
pycparser==2.18
pyfcm==1.3.1
Pygments==2.2.0
python-dateutil==2.6.1
pytz==2017.3
requests==2.18.1
requests-toolbelt==0.8.0
rsa==3.4.2
simplegeneric==0.8.1
six==1.11.0
SQLAlchemy==1.1.14
tenacity==4.4.0
traitlets==4.3.2
urllib3==1.21.1

@sohamsil
Copy link

sohamsil commented Mar 8, 2018

Hello Everyone,

I hope someone found a solution for this issue,

I am still getting the error

google.gax.errors.GaxError: GaxError(RPC failed, caused by <_Rendezvous of RPC that terminated with (StatusCode.PERMISSION_DENIED, Google Cloud Speech API has not been used in project cloud-devshell-dev before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=cloud-devshell-dev then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.)>)

I have installed the packages mentioned by @FingerLiu . But still I am getting the same error message.

Note: Google SPeech API is enabled and I am using Python 3.6

Here is the code, thank you for your help.

 import argparse
 import io

 from google.oauth2 import service_account

 scope = 'https://www.googleapis.com/auth/drive'
 credentials = service_account.Credentials.from_service_account_file('Speech2Text-
 71ae27307424.json',scopes=(scope,))

 def transcribe_file_with_word_time_offsets(speech_file):
     """Transcribe the given audio file synchronously and output the word time
     offsets."""
     print("Start")
    
     from google.cloud import speech
     from google.cloud.speech import enums
     from google.cloud.speech import types   
    
     print("checking credentials")
    
     client = speech.SpeechClient(credentials=credentials)

     print("Checked")
     with io.open(speech_file, 'rb') as audio_file:
          content = audio_file.read()
        
     print("audio file read")    
    
     audio = types.RecognitionAudio(content=content)
    
     print("config start")
     config = types.RecognitionConfig(
             encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
             sample_rate_hertz=16000,
             language_code='en-US',
             enable_word_time_offsets=True)
    
     print("Recognizing:")
     response = client.recognize(config, audio) ## MAJOR PROBLEM
     print("Recognized")
 
     for result in response.results:
         alternative = result.alternatives[0]
         print('Transcript: {}'.format(alternative.transcript))
 
         for word_info in alternative.words:
             word = word_info.word
             start_time = word_info.start_time
             end_time = word_info.end_time
             print('Word: {}, start_time: {}, end_time: {}'.format(
                 word,
                 start_time.seconds + start_time.nanos * 1e-9,
                 end_time.seconds + end_time.nanos * 1e-9))
 
 def transcribe_gcs_with_word_time_offsets(gcs_uri):
     """Transcribe the given audio file asynchronously and output the word time
     offsets."""
     from google.cloud import speech
     from google.cloud.speech import enums
     from google.cloud.speech import types
     client = speech.SpeechClient()
 
     audio = types.RecognitionAudio(uri=gcs_uri)
     config = types.RecognitionConfig(
         encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
         sample_rate_hertz=16000,
         language_code='en-US',
         enable_word_time_offsets=True)
 
     operation = client.long_running_recognize(config, audio)
 
     print('Waiting for operation to complete...')
     result = operation.result(timeout=90)
 
     for result in result.results:
         alternative = result.alternatives[0]
         print('Transcript: {}'.format(alternative.transcript))
         print('Confidence: {}'.format(alternative.confidence))
 
         for word_info in alternative.words:
             word = word_info.word
             start_time = word_info.start_time
             end_time = word_info.end_time
             print('Word: {}, start_time: {}, end_time: {}'.format(
                 word,
                 start_time.seconds + start_time.nanos * 1e-9,
                 end_time.seconds + end_time.nanos * 1e-9))

 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description=__doc__,
         formatter_class=argparse.RawDescriptionHelpFormatter)
     parser.add_argument(dest='path', help='File or GCS path for audio file to be recognized')
     args = parser.parse_args()
     if args.path.startswith('gs://'):
         transcribe_gcs_with_word_time_offsets(args.path)
     else:
         transcribe_file_with_word_time_offsets(args.path)

@chemelnucfin
Copy link
Contributor

@sohamsil There are a couple of things you can try. First of all, we deprecated the gax library. Try upgrading the package by using pip install -U google-cloud-speech.

Second, you can go to console.cloud.google.com and the api and services tab and enable the speech api.

Please let us know if you need more assistance or this has solved your problem.

@sohamsil
Copy link

sohamsil commented Mar 8, 2018

@chemelnucfin Thanks for the prompt reply.

I checked the speech API in console.cloud.google.com and it was enabled.
Ran pip install -U google-cloud-speech successfully.

But still getting the same error and also it gave me 403 request error.

google.api_core.exceptions.PermissionDenied: 403 Request had insufficient authentication scopes.

Kindly look into this.

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 Pub/Sub API. auth grpc priority: p2 Moderately-important priority. Fix may not be included in next release. 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