Python Google Cloud Natural Language API returns Bad Gateway error with status 502

我只是一个虾纸丫 提交于 2019-12-25 00:36:52

问题


I'm working on a project using Python(3.6) and Django(2) in which I need to process all text files from a directory using Google's Natural Language API python's Client. At the moment, there are 30 text files in my folder for testing purpose, the programs perform sentiment_analysis on 28 files but when reached 29th file it returns an error like below:

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

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

[19/Dec/2018 10:08:41] "POST / HTTP/1.1" 500 15145

Here's how I'm using the python's client:

def nlp_text_manager(text_path, name):
    text = text_path
    txt = Path(text_path).read_text(encoding='cp1252')
    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

The Traceback points out the response = service_request.execute() line inside the nlp_text_manager function.

What can be wrong here? Thanks in advance!

来源:https://stackoverflow.com/questions/53849075/python-google-cloud-natural-language-api-returns-bad-gateway-error-with-status-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!