authentication - 为什么 Google Cloud Translate 无法提供持久性 503 服务?
问题描述
每当我向 Gcloud Translate 发出请求时,我都会收到 503 错误:“此时服务不可用”。
以下是使用 Python API 的步骤:
>>> import os
>>> from google.cloud import translate_v2 as translate
>>> source_lang_code = 'nl'
>>> target_lang_code = 'en'
>>> os.environ['GOOGLE_APPLICATION_CREDENTIALS']
'/home/Documents/translate/[..keyfilename...].json'
>>> txt = open( ifn, 'r' ).read()
>>> txt[-10:]
'tuurlijk.\n'
>>> translator = translate.Client()
>>> T = translator.translate( txt, source_language=source_lang_code, target_language=target_lang_code )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/yoozer/anaconda3/lib/python3.7/site-packages/google/cloud/translate_v2/client.py", line 268, in translate
response = self._connection.api_request(method="POST", path="", data=data)
File "/home/yoozer/anaconda3/lib/python3.7/site-packages/google/cloud/_http.py", line 393, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.ServiceUnavailable: 503 POST https://translation.googleapis.com/language/translate/v2: The service is unavailable at this time.
解决方案
您的代码在这里没有问题。HTTP 503 表示它是在服务请求时出现问题的服务。你应该过一段时间再试试。
如果您查看 503 的定义,它会说:
由于临时过载或计划维护,服务器当前无法处理请求,延迟一段时间后可能会得到缓解。
推荐阅读
- python - 我正在做我的第一个 tkinter 项目,我需要一些指导
- angular - 将 moment.js 排除在我的 Angular 构建输出之外
- javascript - 在传单折线中显示时间
- reactjs - React Admin:如何在返回前运行方法
表单视图 - reactjs - React-redux 空值存储为字符串
- sql - Oracle SQL IF ELSE CALCULATION GIVE ME ',',
- javascript - 添加指向基本 HTML/JavaScript 鼠标悬停/弹出窗口的链接
- python-3.x - 为什么绕过回调函数
- node.js - 来自 React-Native App 的 Nodejs 中的分页(ORM Sequelize)
- c# - 从另一个 ViewModel 访问 ViewModel 中的方法