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