2

我有以下 pycurl 代码:

curl = pycurl.Curl()
foo = StringIO()
curl.setopt(pycurl.WRITEFUNCTION, foo.write)
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.URL, finalURL)
curl.setopt(pycurl.POSTFIELDS, encodedArgs)
curl.perform()
responseCode = curl.getinfo(pycurl.RESPONSE_CODE)
effectiveURL = curl.getinfo(pycurl.EFFECTIVE_URL)
curl.close()

当命令行 curl 命令返回时,我看到:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Content-Length: 216
Date: Thu, 06 Jan 2011 15:49:36 GMT
Some XML Error Here: Something you are trying to do is not permitted.

但我从 pycurl 看不到这一点。
使用 pycurl 时如何提取此警报/错误消息?

4

1 回答 1

1

来自服务器的响应是使用 curl 选项编写的pycurl.WRITEFUNCTION

在您的情况下,由于您向它传递了一个StringIO对象,因此响应数据应该在foo变量中:foo.getvalue()

参考: http: //pycurl.sourceforge.net/doc/curlobject.html

于 2011-01-06T16:36:54.173 回答