0

I'm working on a project using Python(3.6) and Django(2) in which I need to process too many(~ 50k) files from a directory by using Google cloud natural language processing API, but after processing ~400 files it returns an error as:

Note: I have googled a lot, so don't mark this as duplicate, please!

raise HttpError(resp, content, uri=self.uri)

googleapiclient.errors.HttpError: https://language.googleapis.com/v1beta2/documents:analyzeSentiment?alt=json returned "Bad Gateway">

[30/Dec/2018 05:10:03] "POST / HTTP/1.1" 500 15162

Here's from views.py:

def nlp_text_manager(text_path, name):
    text = text_path
    # encoding = predict_encoding(text_path)
    # print('encoding is: {}'.format(encoding))
    txt = Path(text_path).read_text(encoding='utf8')
    service = discovery.build('language', 'v1beta2', credentials=credentials)
    service_request = service.documents().analyzeSentiment(
        body={
            'document': {
                'type': 'PLAIN_TEXT',
                'content': txt
            }
        }
    )
    response = service_request.execute()
    return response
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
  • General rule about HTTP codes: 4xx - you failed, 5xx - they failed. – Klaus D. Dec 30 '18 at 05:25
  • is there any explanation about this error? – Abdul Rehman Dec 30 '18 at 07:49
  • The official description is "The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.". In other words: somethings wrong with the API servers. – Klaus D. Dec 30 '18 at 08:33
  • Any docs resource for detail? – Abdul Rehman Dec 30 '18 at 08:40
  • Do you expect Google to publish documentation on their infrastructure problems? – Klaus D. Dec 30 '18 at 09:58
  • Possible duplicate of [Python Google Cloud Natural Language API returns Bad Gateway error with status 502](https://stackoverflow.com/questions/53849075/python-google-cloud-natural-language-api-returns-bad-gateway-error-with-status-5) – Dustin Ingram Jan 02 '19 at 20:31
  • Hi. I work on NL API at Google. Is this happening consistently? Very rare 5xx errors could happen, but if this is happening every time your run this after processing a bunch of docs, then something else might be happening – Mona Attariyan Jan 04 '19 at 01:55
  • Hi @MonaAttariyan yes, it’s happening consistently every time after processing a bunch if docs. – Abdul Rehman Jan 04 '19 at 02:57

0 Answers0