1

Hi i am working on Google Cloud API, when i try to run the demo program given on GC documentation, for the following code

from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

# Instantiates a client
client = language.LanguageServiceClient()

# The text to analyze
text = u'Hello, world!'
document = types.Document(
    content=text,
    type=enums.Document.Type.PLAIN_TEXT)

# Detects the sentiment of the text
sentiment = client.analyze_sentiment(document=document).document_sentiment

print('Text: {}'.format(text))
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))

The code doesn't run when it hits this statement sentiment = client.analyze_sentiment(document=document).document_sentiment

and gives the following long error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/language_v1/gapic/language_service_client.py", line 247
, in analyze_sentiment
    request, retry=retry, timeout=timeout, metadata=metadata
  File "/usr/local/lib/python2.7/dist-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 277, in retry_wrapped_func
    on_error=on_error,
  File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 202, in retry_target
    last_exc,
  File "/usr/lib/python2.7/dist-packages/six.py", line 718, in raise_from
    raise value
google.api_core.exceptions.RetryError: Deadline of 600.0s exceeded while calling <functools.partial object at 0x7f9
527b06fc8>, last exception: 503 Getting metadata from plugin failed with error: ('Failed to retrieve http://metadat
a.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Engi
nemetadata service. Status: 404 Response:\n<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=vi
ewport content="initial-scale=1, minimum-scale=1, width=device-width">\n  <title>Error 404 (Not Found)!!1</title>\n
  <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;paddi
ng:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.go
ogle.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{c
olor:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0
;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_col
or_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//w
ww.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-im
age:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-w
ebkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_colo
r_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n 
 </style>\n  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n  <p><b>404.</b> <ins>That\xe2\
x80\x99s an error.</ins>\n  <p>The requested URL <code>/computeMetadata/v1/instance/service-accounts/default/?recur
sive=true</code> was not found on this server.  <ins>That\xe2\x80\x99s all we know.</ins>\n', <google.auth.transpor
t.requests._Response object at 0x7f9527b22710>)

how to i debug this error any help will be really appreciated, thank you

  • Are you running this code on your desktop, meaning not on a Google Compute instance? You have the question tagged `google-cloud-functions`. The error is caused by not being able to access the metadata server to get credentials (access tokens). – John Hanley Oct 22 '19 at 12:33
  • i am actually using Google Cloud's terminal using a VM. – lalith Shankar Oct 23 '19 at 09:19
  • i have debugged the code and i am getting a Traceback and Attribute Error File "", line 1, in AttributeError: 'tuple' object has no attribute 'score' for e in entities: ... print(e.name, e.entity_type, e.metadata, e.salience) ... Traceback (most recent call last): File "", line 2, in – lalith Shankar Oct 23 '19 at 09:22

1 Answers1

0

I’ve tried to replicate the issue but I was having a different error at my local test, since after the retry logic it failed due to a request timeout. Then I tried the same code at the cloud functions environment and it was working correctly.

My local env was the Cloud Shell, I’m afraid that this could be a problem from a recent outage in cloud networking.

To debug into your local environment you can use this tutorial.

sergio franco
  • 346
  • 2
  • 10