Python pycurl:RETURNTRANSFER选项不';不存在

Python pycurl:RETURNTRANSFER选项不';不存在,python,curl,libcurl,pycurl,attributeerror,Python,Curl,Libcurl,Pycurl,Attributeerror,我使用pycurl访问JSON web API,但当我尝试使用以下内容时: ocurl.setopt(pycurl.URL, gaurl) # host + endpoint ocurl.setopt(pycurl.RETURNTRANSFER, 1) ocurl.setopt(pycurl.HTTPHEADER, gaheader) # Send extra headers ocurl.setopt(pycurl.CUSTOMREQUEST, "POST") # HTTP POST

我使用pycurl访问JSON web API,但当我尝试使用以下内容时:

ocurl.setopt(pycurl.URL, gaurl)       # host + endpoint
ocurl.setopt(pycurl.RETURNTRANSFER, 1)
ocurl.setopt(pycurl.HTTPHEADER, gaheader) # Send extra headers
ocurl.setopt(pycurl.CUSTOMREQUEST, "POST") # HTTP POST req
ocurl.setopt(pycurl.CONNECTTIMEOUT, 2)
然后执行脚本,它失败了

File "getdata.py", line 46, in apicall
ocurl.setopt(pycurl.RETURNTRANSFER, 1)
AttributeError: 'module' object has no attribute 'RETURNTRANSFER'

我不知道发生了什么,也不知道为什么RETURNTRANSFER看起来不存在,而所有其他选项都存在。

您是否尝试过执行
print dir(pycurl)
并查看属性列表中是否存在该选项?

手册显示了以下用法:

导入pycurl >>>导入StringIO >>>b=StringIO.StringIO() >>>conn=pycurl.Curl() >>>conn.setopt(pycurl.URL,'http://www.example.org') >>>conn.setopt(pycurl.WRITEFUNCTION,b.write) >>>康涅狄格州执行 >>>打印b.getvalue() 示例网页 您已通过键入“example.com”到达此网页, “示例.net”, 或“example.org”进入您的web浏览器

这些域名保留在文档中使用,不可用 E 申请注册。见,第3节


看起来有点迂回,但我不是PycURL的忠实粉丝…

CURLOPT\u RETURNTRANSFER不是libcurl选项,它是在PHP/CURL绑定中提供的

是的,它工作得很好。我想知道他们为什么不从一开始就实施RETURNTRANSFER。
>>> import pycurl
>>> import StringIO
>>> b = StringIO.StringIO()
>>> conn = pycurl.Curl()
>>> conn.setopt(pycurl.URL, 'http://www.example.org')
>>> conn.setopt(pycurl.WRITEFUNCTION, b.write)
>>> conn.perform()
>>> print b.getvalue()
<HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not availabl
e
  for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC

  2606</a>, Section 3.</p>
</BODY>
</HTML>