- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 pycurl 中取消传输?我曾经在 libcurl 中返回 -1 但 pycurl 似乎不喜欢那样(“pycurl.error:写入回调 -1 17 的返回值无效”)返回 0 也不起作用,我得到“错误:(23,'写入主体失败')”。另外我如何使用 pycurl 进行尝试/除外?我没有看到任何在线示例,也没有看到网站上的 pycurl 示例
最佳答案
示例代码在这里会有帮助。从错误消息来看,并在源代码中查找它,您已经设置了一个写入回调。我认为这是由 CURLOPT_WRITEFUNCTION 配置的,其文档如下:
Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it'll signal an error to the library and it will abort the transfer and return CURLE_WRITE_ERROR.
pycurl 包装器代码检查该值是否在 0 和传递给它的数字之间。这就是为什么 -1 失败,以及为什么 0 触发 CURLE_WRITE_ERROR,引发“写入正文失败”异常。 pycurl 代码是:
/* run callback */
arglist = Py_BuildValue("(s#)", ptr, total_size);
if (arglist == NULL)
goto verbose_error;
result = PyEval_CallObject(cb, arglist);
Py_DECREF(arglist);
if (result == NULL)
goto verbose_error;
/* handle result */
if (result == Py_None) {
ret = total_size; /* None means success */
}
else if (PyInt_Check(result)) {
long obj_size = PyInt_AsLong(result);
if (obj_size < 0 || obj_size > total_size) {
PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
goto verbose_error;
}
ret = (size_t) obj_size; /* success */
}
else if (PyLong_Check(result)) {
... identical code for Long ...
}
else {
PyErr_SetString(ErrorObject, "write callback must return int or None");
goto verbose_error;
}
我在 pycurl 中没有看到该函数有任何方法支持另一个返回值。可能还有其他方法,例如设置进度回调,这似乎允许中止。
curl本身的相关代码是:
/* If the previous block of data ended with CR and this block of data is
just a NL, then the length might be zero */
if(len) {
wrote = data->set.fwrite_func(ptr, 1, len, data->set.out);
}
else {
wrote = len;
}
if(CURL_WRITEFUNC_PAUSE == wrote)
return pausewrite(data, type, ptr, len);
if(wrote != len) {
failf(data, "Failed writing body (%d != %d)", (int)wrote, (int)len);
return CURLE_WRITE_ERROR;
}
所以你可以看到pycurl不支持返回curl本身允许的CURL_WRITEFUNC_PAUSE。还可以看到curl没有办法通过write回调函数支持中止。您将不得不使用其他东西。
关于python - pycurl 取消传输并尝试 & except,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/526325/
我只想知道下面两种说法的区别: curl.setopt(pycurl.WRITEDATA, fp) curl.setopt(pycurl.WRITEFUNCTION, fp.write) fp 是一个
我正在将 ebay sdk 移植到 python3,我偶然发现了以下问题。 我正在使用 pycurl 发送一些 HTTP 请求。这是我的配置方式: self._curl = pycurl.Cu
我将我的 mac 更新到 high sierra,现在我无法安装 pycurl。它失败并显示以下消息:Curl 已配置为使用 SSL,但我们无法确定它使用的是哪个 SSL 后端。请参阅 PycURL
我想获取响应中携带的Cookie(Set-Cookie: name=value; ...)。 传递信息常量和空列表的引用时: set_cookies = [] c.getinfo(c.COOKIELI
使用您向其发送请求的 API 处理一个小项目,然后它会返回一个带有 zip 文件的响应,然后您可以下载该文件。我第一次自动下载时尝试使用 setopt(curl.WRITEDATA, fp) 函数,但
我编写了一个脚本来从 Qualys 获取扫描结果,每周运行一次以收集指标。 此脚本的第一部分涉及获取过去一周运行的每个扫描的引用列表以进行进一步处理。 问题是,虽然有时这会完美地工作,但有时脚本会卡在
我创建了一个 python 3 脚本,允许我在搜索引擎 (DuckDuckGo) 上进行搜索,获取 HTML 源代码并将其写入文本文件。 import pycurl from io import By
在我的系统 (MAC OS X) 中尝试安装 pycurl 时,出现以下错误。不知道如何解决它。请帮忙!!! nsh$ sudo easy_install pycurl Searching
我正在尝试进行一些网络抓取,它涉及发送一个带有多选框列表的表单,看起来与此类似: value1 value2 现在,我想使用 pycurl 发送 value1 和 value2,例
在我的 PC (Windows 10 x64) 上安装了一个新的、干净的系统后,我遇到了 python 的 pycurl 库的一些问题(当然)。 我在 Python 2.7 和 3.4 上尝试过这个
我有一个很大的 URL 列表,我必须并行下载它并检查每个响应返回的 header 之一。 我可以使用 CurlMulti用于并行化。我可以使用 /dev/null 作为 fb,因为我对正文不感兴趣,只
我在 python 中使用 pycurl 向 URL 发出请求,该 URL 返回相当大的 json 格式响应。当我在浏览器中转到 URL 时,我看到了全部内容,但是如果我使用 pycurl 并打印接收
我似乎无法让 RESUME_FROM 选项起作用。这是我一直在测试的一些示例代码: import os import pycurl import sys def progress(total, exi
使用 pycurl 时查看已设置哪些选项(opt)的最佳方法是什么? 例如,我调用一个返回 pycurl 对象的方法。我想做的是调用电话查看已设置的 opts (pycurl.setopts)。 最佳
我创建了一个网络服务 bottle并将其用作 JSON 接口(interface)。该例程正在收集信息,检查 URL 的有效性和 http_code。 def get_statuscode(url):
下面是一段上传文件的代码: file_size = os.path.getsize('Tea.rdf') f = file('Tea.rdf') c = pycurl.Curl() c
好吧,我认为问题的标题很容易解释,所以你可能不需要继续阅读,但这里是这样的: 我一直在使用 PyCurl有一段时间,我总是使用 curlConnector = pycurl.Curl() curlCo
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: curl on app engine GAE 支持 pycurl 吗? 我已经从这个链接下载了 pycurl
我什么都试过了!我找不到在我的 Windows 7 机器上安装 pyCurl 的方法! 我找到了这些二进制文件 link ... 但是 2.6 没有二进制文件。 :( 帮助会很大。 :) 最佳答案 这
我是初学者,使用 Python 和 Pycurl 进行网页压力测试。但是,pycurl 不断在终端中打印出返回的 html,这使得压力测试花费的时间比它应该花费的时间还要多。我正在使用的一个这样的 p
我是一名优秀的程序员,十分优秀!