首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误: 503 DNS解析在Google转换API中失败,但仅在通过终端执行Python文件时才失败。

错误: 503 DNS解析在Google转换API中失败,但仅在通过终端执行Python文件时才失败。
EN

Stack Overflow用户
提问于 2020-03-23 10:18:02
回答 1查看 2.9K关注 0票数 0

当使用带有JSON授权密钥的Google时,我遇到了一个奇怪的问题。我可以直接在我选择的编辑器(VSCode)中运行该文件,而不会出现任何问题。没有错误。

但是,当我通过终端运行同一个文件时,该文件将一直执行到从磁盘加载Google转换凭据之后。然后调用在错误消息下面抛出。

因为只有在从终端运行文件时才会发生这种情况,所以我发现这个bug很难解决。

目标是让这个文件收集数据,并使用Google服务翻译一些字段,然后将数据存储在数据库中。

下面是错误消息:

代码语言:javascript
运行
复制
    Error: 503 DNS resolution failed
    Traceback (most recent call last):
      File "/home/MY-USER-NAME/anaconda3/lib/python3.6/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
      File "/home/MY-USER-NAME/anaconda3/lib/python3.6/site-packages/grpc/_channel.py", line 690, in __call__
      File "/home/MY-USER-NAME/anaconda3/lib/python3.6/site-packages/grpc/_channel.py", line 592, in _end_unary_response_blocking
    grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
            status = StatusCode.UNAVAILABLE
            details = "DNS resolution failed"
            debug_error_string = "{"created":"@1584629013.091398712","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3934,"referenced_errors":[{"created":"@1584629013.091395769","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":262,"referenced_errors":[{"created":"@1584629013.091394954","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":370,"grpc_status":14,"referenced_errors":[{"created":"@1584629013.091389655","description":"C-ares status is not ARES_SUCCESS: Could not contact DNS servers","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244,"referenced_errors":[{"created":"@1584629013.091380513","description":"C-ares status is not ARES_SUCCESS: Could not contact DNS servers","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244}]}]}]}]}"
    >

这是我代码的相关部分:

  1. 专用CRON文件(我在许多其他项目中使用这个两步设置,没有任何问题)
代码语言:javascript
运行
复制
#! anaconda3/bin/python

import os 
os.chdir(r'/home/MY-USER-NAME/path-to-project')

import code-file
  1. 代码文件(简单的.py脚本)
代码语言:javascript
运行
复制
[...]

from google.oauth2 import service_account
from google.cloud import translate

key_path = 'path-to-file/credentials.json'
credentials = service_account.Credentials.from_service_account_file(
key_path, scopes=['https://www.googleapis.com/auth/cloud-platform'])

def translate_to_en(contents, credentials=None, verbose=False, use_pinyin=False):

            [...]

            client = translate.TranslationServiceClient(credentials=credentials)  
            parent = client.location_path(credentials.project_id, 'global')

            [...]

            response = client.translate_text(
              parent=parent,
              contents=[contents],
              mime_type='text/plain',  # mime types: text/plain, text/html
              target_language_code='en-US')

            [...]


[...]

for c in trans_cols:
    df[f'{c}__trans'] = df[c].apply(lambda x: translate_to_en(contents=x, credentials=credentials, verbose=False))

[...]

如果有人有一个好主意来解决这个问题,我们将非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-03-23 15:39:19

这个问题似乎与github中报告的grpc 错误有关。对于gRPC名称解析,您可以在github上遵循这位医生

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60811596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档