异常:503 将数据推送到 Google Pub/Sub 时连接到所有地址失败

Posted

技术标签:

【中文标题】异常:503 将数据推送到 Google Pub/Sub 时连接到所有地址失败【英文标题】:exception: 503 failed to connect to all addresses when pulishing data to Google Pub/Sub 【发布时间】:2021-09-30 02:48:14 【问题描述】:

我使用的是 Google Pub/Sub 教程中的示例代码。尝试发布消息时,抛出异常:503 无法连接到所有地址。我将 Pub/Sub 发布者角色授予服务帐户。直到前天一切正常。

从控制台或 gcloud 命令发布消息时没有问题。 Cloud Functions 是我的订阅。

这是教程的链接:

https://cloud.google.com/pubsub/docs/samples/pubsub-publish-with-error-handler

以下是软件包及其版本:

cachetools==4.2.2 certifi==2021.5.30  charset-normalizer==2.0.3  
google-api-core==1.31.0  
google-auth==1.33.1  
google-cloud-pubsub==2.6.1  
googleapis-common-protos==1.53.0  
grpc-google-iam-v1==0.12.3  
grpcio==1.39.0  
idna==3.2  libcst==0.3.19  mypy-extensions==0.4.3  packaging==21.0  proto-plus==1.19.0  
protobuf==3.17.3  pyasn1==0.4.8  pyasn1-modules==0.2.8  pyparsing==2.4.7  pytz==2021.1  
PyYAML==5.4.1  requests==2.26.0  rsa==4.7.2  six==1.16.0  typing-extensions==3.10.0.0  
typing-inspect==0.7.1  urllib3==1.26.6  

这是错误代码:

$ python publish-message.py
Failed to publish 10 messages.
Traceback (most recent call last):
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\grpc_helpers.py", line 67, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "E:\gcp-pubsub-cs\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "E:\gcp-pubsub-cs\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = ""created":"@1626984490.444000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3009,"referenced_errors":["created":"@1626984490.444000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14]"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\retry.py", line 188, in retry_target
    return target()
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\timeout.py", line 102, in func_with_timeout
    return func(*args, **kwargs)
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\grpc_helpers.py", line 69, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\gcp-pubsub-cs\lib\site-packages\google\cloud\pubsub_v1\publisher\_batch\thread.py", line 268, in _commit
    response = self._client.api.publish(
  File "E:\gcp-pubsub-cs\lib\site-packages\google\pubsub_v1\services\publisher\client.py", line 613, in publish
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\retry.py", line 285, in retry_wrapped_func
    return retry_target(
  File "E:\gcp-pubsub-cs\lib\site-packages\google\api_core\retry.py", line 203, in retry_target
    six.raise_from(
  File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 60.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x000002A99F2BF0D0>, topic: "projects/stream-analytics-21/topics/twitter-stream"
messages 
  data: "0"

messages 
  data: "1"

messages 
  data: "2"

messages 
  data: "3"

messages 
  data: "4"

messages 
  data: "5"

messages 
  data: "6"

messages 
  data: "7"

messages 
  data: "8"

messages 
  data: "9"

, metadata=[('x-goog-request-params', 'topic=projects/stream-analytics-21/topics/twitter-stream'), ('x-goog-api-client', 'gl-python/3.9.6 grpc/1.39.0 gax/1.31.0 gccl/2.6.1')]), last exception: 503 failed to connect to all addresses
Please handle Deadline of 60.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x000002A99F2BF0D0>, topic: "projects/stream-analytics-21/topics/twitter-stream"

提前谢谢你!!

【问题讨论】:

您是否对cloud.google.com/pubsub/docs/samples/… 的示例代码进行了任何修改?如果是这样,您能否附上您所做的更改? 此外,您是否按照cloud.google.com/pubsub/docs/… 将GOOGLE_APPLICATION_CREDENTIALS 环境变量设置为您的服务帐户密钥文件? @Lauren 解决了这个问题。看起来我正在使用另一个会话中的 GOOGLE_APPLICATION_CREDENTIALS。太感谢了。我怎么给你这个功劳? 【参考方案1】:

将答案发布为 wiki。根据@Lauren 和@Ranaveer 的讨论,在当前会话中设置GOOGLE_APPLICATION_CREDENTIALS 时问题已得到解决。

【讨论】:

以上是关于异常:503 将数据推送到 Google Pub/Sub 时连接到所有地址失败的主要内容,如果未能解决你的问题,请参考以下文章

如何将 Google Cloud Platform Pub/Sub 消息推送到 C# 桌面应用程序

已成功上传到 Heroku Local,但一旦推送到 Heroku live 就会出现 503 错误

是否可以将 redis 键空间通知推送到 redis 流而不是 pub/sub 通道

将 Angular 中的点击发送到 Google Pub/Sub

使用python和管理api将外部数据推送到google analytics 360

来自/到 pubsub 和 websocket 的实时转换推送到客户端