Pycurl 保持活动与 Curl.perform 一起工作,但在使用 CurlMulti 时经常断开连接

问题描述

我想将 multicurl 用于双工功能。正常的 curl.perform 可以很好地保持连接很长时间。

c = pycurl.Curl()
c.setopt(c.VERBOSE,True)
c.setopt(c.URL,'https://someurl.com')
c.setopt(c.POSTFIELDS,postfields)
c.perform()
time.sleep(60)
c.perform()
time.sleep(60)
c.perform()

但是,当我使用以下简化代码时,它会频繁断开连接:

m = pycurl.CurlMulti()
c.setopt(c.POSTFIELDS,postfields)
m.add_handle(c)
while 1:
    (result,num) = m.perform()
    status = m.select(1)
    if num == 0: break
m.remove_handle(c)
time.sleep(10)
repeat this several times

我尝试了 HTTP 1.1 和 HTTP2(想使用 HTTP2),但我不知道差异来自哪里。 版本信息:PycURL PycURL/7.43.0.5 libcurl/7.68.0 OpenSSL/1.1.1d zlib/1.2.11 c-ares/1.15.0 WinIDN libssh2/1.9.0 nghttp2/1.40.0(针对0x74400编译)

一些可能有帮助的调试信息(它们来自不同的断开连接),在重复 curl.perform 操作时这些错误都没有出现:

old SSL session ID is stale,removing
....
Connection 0 seems to be dead!
Closing connection 0
48 bytes stray data read before trying h2 connection
....
OpenSSL SSL_read: Connection was aborted,errno 10053
Failed receiving HTTP2 data
Connection died,retrying a fresh connect

编辑: 我发现 Pycurl 7.43.0 确实可以与 http 1.1 正常工作,但找不到支持 http2 的 Windows 版本。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)