【问题标题】:Why Stripe gives me this error every few hours: Network error: ConnectionError:为什么 Stripe 每隔几个小时就给我这个错误:网络错误:ConnectionError:
【发布时间】:2022-01-26 17:38:48
【问题描述】:

我每隔几个小时就会收到以下错误。为什么?

我认为这与 Stripe 支付有关。

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

在处理上述错误期间,还会出现一些其他错误:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/digital/.local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/digital/.local/lib/python3.8/site-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/http_client.py", line 286, in request
    result = self._thread_local.session.request(
  File "/home/digital/.local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/digital/.local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/digital/.local/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/digital/paymentfollower.py", line 145, in paymentfollowing
    newer_charge=stripe.Charge.list(limit=1,ending_before=older_charge_data)
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/api_resources/abstract/listable_api_resource.py", line 23, in list
    response, api_key = requestor.request("get", url, params)
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/api_requestor.py", line 119, in request
    rbody, rcode, rheaders, my_api_key = self.request_raw(
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/api_requestor.py", line 343, in request_raw
    rbody, rcode, rheaders = self._client.request_with_retries(
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/http_client.py", line 151, in request_with_retries
    raise connection_error
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/http_client.py", line 123, in request_with_retries
    response = self.request(method, url, headers, post_data)
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/http_client.py", line 312, in request
    self._handle_request_error(e)
  File "/home/digital/.local/lib/python3.8/site-packages/stripe/http_client.py", line 364, in _handle_request_error
    raise error.APIConnectionError(msg, should_retry=should_retry)
stripe.error.APIConnectionError: Unexpected error communicating with Stripe.  If this problem persists,
let us know at support@stripe.com.

(Network error: ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

Stack-overflow 一直说我的帖子主要是代码,我应该添加更多解释。所以我一直在重复这句话。

Stack-overflow 一直说我的帖子主要是代码,我应该添加更多解释。所以我一直在重复这句话。

【问题讨论】:

  • 当您收到该错误时,您提出了什么要求?这是 Stripe API 调用还是您正在发出另一个请求?
  • 名称为ConnectionError。互联网不可靠,有时您的请求会在途中丢失。这种情况时不时发生是正常的。您应该记录错误,然后重试。 stripe.com/docs/error-handling#network-errors
  • 但看起来您只包含了部分回溯。这仅来自 Python 标准库 urllib3 和 http 模块。但是调用代码是什么?如果没有完整的回溯,我们无法知道它是由 Stripe 库还是其他向远程服务器发出 http 请求的服务引起的。
  • @HåkenLid 我添加了完整的堆栈错误。请再次检查帖子。
  • python-stripe 库还具有内置的自动重试功能。如果你幸运的话,你可以通过增加这个配置值来解决这个问题。 stripe.max_network_retries = 2github.com/stripe/stripe-python#configuring-automatic-retries

标签: python python-3.x stripe-payments


【解决方案1】:

stripe.max_network_retries = 2 为我解决了这个问题,正如 cmets 中所建议的那样。

【讨论】:

    猜你喜欢
    • 2017-01-25
    • 2011-09-07
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2013-11-14
    • 1970-01-01
    相关资源
    最近更新 更多