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



我在GooglePub/Sub教程中使用了示例代码。当尝试发布消息时,引发了异常:503未能连接到所有地址。我将Pub/Sub发布者角色分配给了服务帐户。直到前天一切都很好。

从Console或gcloud命令发布消息时没有问题。云功能是我的订阅。

以下是教程链接:

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-cslibsite-packagesgoogleapi_coregrpc_helpers.py", line 67, in error_remapped_callable
return callable_(*args, **kwargs)
File "E:gcp-pubsub-cslibsite-packagesgrpc_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "E:gcp-pubsub-cslibsite-packagesgrpc_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-cslibsite-packagesgoogleapi_coreretry.py", line 188, in retry_target
return target()
File "E:gcp-pubsub-cslibsite-packagesgoogleapi_coretimeout.py", line 102, in func_with_timeout
return func(*args, **kwargs)
File "E:gcp-pubsub-cslibsite-packagesgoogleapi_coregrpc_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-cslibsite-packagesgooglecloudpubsub_v1publisher_batchthread.py", line 268, in _commit
response = self._client.api.publish(
File "E:gcp-pubsub-cslibsite-packagesgooglepubsub_v1servicespublisherclient.py", line 613, in publish
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
File "E:gcp-pubsub-cslibsite-packagesgoogleapi_coregapic_v1method.py", line 145, in __call__
return wrapped_func(*args, **kwargs)
File "E:gcp-pubsub-cslibsite-packagesgoogleapi_coreretry.py", line 285, in retry_wrapped_func
return retry_target(
File "E:gcp-pubsub-cslibsite-packagesgoogleapi_coreretry.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"

提前感谢!!

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

相关内容

  • 没有找到相关文章

最新更新