python - Python - Google 自然语言处理 API 返回 HttpError 502 bad gateway
问题描述
我正在使用 Python(3.6) 和 Django(2) 开发一个项目,在该项目中我需要使用 Google 云自然语言处理 API 处理目录中的太多(~ 50k)文件,但在处理了 ~400 个文件后它返回错误为:
注意:我搜索了很多,所以请不要将其标记为重复!
引发 HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: https://language.googleapis.com/v1beta2/documents:analyzeSentiment?alt=json 返回“错误网关”>
[2018 年 12 月 30 日 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
解决方案
推荐阅读
- parsing - 该语法是否有运算符语法(弱等效)?
- python - 如何从pyspark的数据框中的爆炸值中附加一个值
- cplex - CPLEX OPL 语法
- javascript - 如何使菜单向上扩展以适应新添加的条目
- signalr-hub - 信号器/js 404(未找到)
- javascript - 反应:Axios 不发布到数据库
- react-native - keycloak有时发送errorMessage如何解决android中的keyClock错误
- c++ - 有没有一种方法可以复制和粘贴数据,同时每次都增加该数据中的数字?
- android - 将 ViewPager2 与 TabLayout 和片段一起使用。能够交换片段,除非用户首先浏览到另一个选项卡,否则不会显示更新的片段
- vb.net - 有人可以帮我解决这个 SOAP 错误描述吗