gpt4 book ai didi

Python urllib3 urlopen 不使用特定错误的重试

转载 作者:太空宇宙 更新时间:2023-11-04 01:16:30 30 4
gpt4 key购买 nike

为什么 urllib3 中的 urlopen 在遇到 ReadTimeoutError 时不重试?我错过了什么吗?我可以使用自己的重试代码来解决这个问题,但我更愿意使用模块中的重试代码。

我什至试图明确地将 retries=3 作为 HTTPSConnectionPool.request() 的参数,但它没有帮助...

这是我的代码:

conn = urllib3.HTTPConnectionPool(host, port=port)
return conn.request(method, api_url, data, retries=3,
timeout=urllib3.Timeout(connect=2, read=3))

谢谢!

编辑:

现在,带有一些调试信息的响应(这是来自 openERP 的日志):

2014-06-18 08:36:42,791 5585 DEBUG test 
openerp.addons.myaddon.xml_request.xml_request: args prepared
2014-06-18 08:36:42,791 DEBUG Added an stderr logging handler to logger:
urllib3
2014-06-18 08:36:42,791 5585 DEBUG test urllib3: Added an stderr logging
handler to logger: urllib3
2014-06-18 08:36:42,792 INFO Starting new HTTPS connection (1):
some.host.com
2014-06-18 08:36:42,792 5585 INFO test urllib3.connectionpool: Starting new
HTTPS connection (1): some.host.com
2014-06-18 08:36:43,699 DEBUG Setting read timeout to 10
2014-06-18 08:36:43,699 5585 DEBUG test urllib3.connectionpool: Setting read
timeout to 10
2014-06-18 08:36:53,722 5585 ERROR test openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
File "/home/openerp/server/openerp/osv/osv.py", line 132, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/openerp/server/openerp/osv/osv.py", line 199, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/openerp/custom_addons/myaddon/xml_request/xml_request.py",
line 260, in button_test
self.request(cr, uid, ids[0], data, context=context)
File "/home/openerp/custom_addons/myaddon/xml_request/xml_request.py",
line 234, in request
config_rec.xml_port, 'POST', api_url, vals)
File "/home/openerp/custom_addons/myaddon/xml_request/xml_request.py",
line 208, in connAndReq
timeout=urllib3.Timeout(connect=5, read=10))
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 79, in
request
**urlopen_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 142, in
request_encode_body
**urlopen_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line
574, in urlopen
raise ReadTimeoutError(self, url, "Read timed out.")
ReadTimeoutError: HTTPSConnectionPool(host=u'some.host.com', port=443): Read
timed out.

如您所见,ReadTimeoutError 在到期时间后立即抛出,没有重试。

最佳答案

看起来这是 urllib3 v1.8.2 中的错误。

应该是fixed here ,在 master 分支中可用。

新版本即将推出。带来不便敬请谅解。 :)

关于Python urllib3 urlopen 不使用特定错误的重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259079/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com