pycurl 取消传输并尝试 & 除了
如何取消 pycurl 中的传输? 我曾经在 libcurl 中返回 -1 但 pycurl 似乎不喜欢那样(“pycurl.error:写入回调 -1 17 的返回值无效”)返回 0 也不起作用,我得到“错误:(23,'写入主体失败')”。 另外我如何使用 pycurl 进行尝试/除外? 我没有看到任何在线示例,也没有看到网站上的 pycurl 示例
How do i cancel a transfer in pycurl? i use to return -1 in libcurl but pycurl doesnt seem to like that ("pycurl.error: invalid return value for write callback -1 17") return 0 doesnt work either, i get "error: (23, 'Failed writing body')" . Also how do i do a try/except with pycurl? i dont see any examples online nor the pycurl examples from the site
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例代码在这里会有帮助。 从错误消息来看,并在源代码中查找它,您已经设置了一个写入回调。 我认为这是由 CURLOPT_WRITEFUNCTION 配置的,其文档说明:
pycurl 包装器代码检查该值是否介于 0 和传递给它的数字之间。 这就是为什么 -1 失败,以及为什么 0 触发 CURLE_WRITE_ERROR,引发“写入正文失败”异常。 pycurl 代码是:
我在 pycurl 中没有看到该函数有任何方法支持另一个返回值。 可能还有其他方法,例如设置进度回调,这似乎允许中止。
curl本身的相关代码是:
所以你可以看到pycurl不支持返回curl本身允许的CURL_WRITEFUNC_PAUSE。 还可以看到curl没有办法通过write回调函数支持中止。 你将不得不使用其他东西。
Example code would help here. Judging from the error message, and grepping for it in the source code, you've set up a write callback. This is configured, I think, by CURLOPT_WRITEFUNCTION, and the documentation for that says:
The pycurl wrapper code checks that the value is between 0 and the number passed to it. That's why -1 failed, and why 0, triggers CURLE_WRITE_ERROR, raises the "failed writing body" exception. The pycurl code is:
I don't see any way in pycurl for this function to support another return value. There might be other ways, like setting up a progress callback, which does seem to allow aborts.
The relevant code in curl itself is:
so you can see that pycurl does not support returning the CURL_WRITEFUNC_PAUSE which curl itself allows. You can also see that curl has no way to support aborts through the write callback function. You will have to use something else.