Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何调试此堆栈跟踪?(google.auth.transport.grpc.AuthMetadataPlugin)_Python 3.x_Google Cloud Platform_Google Cloud Functions_Google Cloud Logging - Fatal编程技术网

Python 3.x 如何调试此堆栈跟踪?(google.auth.transport.grpc.AuthMetadataPlugin)

Python 3.x 如何调试此堆栈跟踪?(google.auth.transport.grpc.AuthMetadataPlugin),python-3.x,google-cloud-platform,google-cloud-functions,google-cloud-logging,Python 3.x,Google Cloud Platform,Google Cloud Functions,Google Cloud Logging,我创建了一个函数: 通过云调度程序每分钟运行一次 从云存储桶中以字符串形式读取blob 将消息写入子主题 我收到的连接错误大约有5%的时间是引用python站点包而不是我的实际代码。如何继续调试此问题 我在读取云存储的每一步都添加了重试,但这种失败似乎发生在我的代码开始运行之前。或者,日志没有到达stackdriver 这是完整的堆栈跟踪。我看不出它在我的代码中引用了什么行 Function execution started AuthMetadataPluginCallback "<

我创建了一个函数:

  • 通过云调度程序每分钟运行一次
  • 从云存储桶中以字符串形式读取blob
  • 将消息写入子主题
我收到的连接错误大约有5%的时间是引用python站点包而不是我的实际代码。如何继续调试此问题

我在读取云存储的每一步都添加了重试,但这种失败似乎发生在我的代码开始运行之前。或者,日志没有到达stackdriver

这是完整的堆栈跟踪。我看不出它在我的代码中引用了什么行

Function execution started
AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x7ea453f9e780>" raised exception!
Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 977, in send
    self.sock.sendall(data)
ConnectionResetError: [Errno 104] Connection reset by peer
None
During handling of the above exception, another exception occurred:
None
Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/env/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/env/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 977, in send
    self.sock.sendall(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
None
During handling of the above exception, another exception occurred:
None
Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/auth/transport/requests.py", line 123, in __call__
    method, url, data=body, headers=headers, timeout=timeout, **kwargs
  File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
None
The above exception was the direct cause of the following exception:
None
Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 96, in refresh
    self._retrieve_info(request)
  File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 77, in _retrieve_info
    request, service_account=self._service_account_email
  File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 200, in get_service_account_info
    recursive=True,
  File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 132, in get
    response = request(url=url, method="GET", headers=_METADATA_HEADERS)
  File "/env/local/lib/python3.7/site-packages/google/auth/transport/requests.py", line 128, in __call__
    six.raise_from(new_exc, caught_exc)
  File "<string>", line 3, in raise_from
google.auth.exceptions.TransportError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
None
The above exception was the direct cause of the following exception:
None
Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/grpc/_plugin_wrapping.py", line 79, in __call__
    callback_state, callback))
  File "/env/local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 77, in __call__
    callback(self._get_authorization_headers(context), None)
  File "/env/local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 64, in _get_authorization_headers
    self._request, context.method_name, context.service_url, headers
  File "/env/local/lib/python3.7/site-packages/google/auth/credentials.py", line 124, in before_request
    self.refresh(request)
  File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 102, in refresh
    six.raise_from(new_exc, caught_exc)
  File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

我希望知道为什么这种连接错误如此频繁。

我已经发现了这种间歇性错误的原因

GCP最佳实践建议在
main.py中实例化
main()
之外的客户端连接。这些仅在实例冷启动时执行

例如:

[main.py]-仅在冷启动期间实例化客户端

import builtins
from google.cloud import storage
from google.cloud import pubsub_v1
from google.cloud import logging as cloudlogging

# Create global clients to avoid unneeded network activity!
builtins.pubsub_client = pubsub_v1.PublisherClient()
builtins.storage_client = storage.Client()
builtins.log_client = cloudlogging.Client()
[其他函数py]-使用客户端

bucket = storage_client.create_bucket(bucket_name)


例如,我意识到在PyCharm IDE中无法识别带有
内置项的引用(一直显示假阳性未声明的错误)。你做了些什么来解决这个问题吗?这和我使用的过梁在崇高的文本中是一样的。我只需手动确认我已在内置中声明。所以。。。解决方案是什么?@notacorn在回答中描述了全球客户机
bucket = storage_client.create_bucket(bucket_name)