Python-Google自然语言处理API返回HttpError 502错误的网关

时间:2018-12-30 05:20:26

标签: python google-cloud-python natural-language-processing google-natural-language

我正在使用Python(3.6)和Django(2)开发一个项目,在该项目中,我需要使用Google云自然语言处理API处理目录中的太多文件(约50k),但处理了约400个文件文件返回错误为:

  

注意:我已经在Google上搜索了很多,所以请不要将其标记为重复!

     

引发HttpError(resp,content,uri = self.uri)

     

googleapiclient.errors.HttpError:https://language.googleapis.com/v1beta2/documents:analyzeSentiment?alt=json返回了“错误的网关”

     

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

这里来自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

0 个答案:

没有答案