我正在使用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。

有帮助吗?

解决方案

手册显示了用法 这样的东西:

>>> 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>

似乎有点回旋处,但我不是Pycurl的忠实拥护者...

其他提示

curlopt_returntransfer不是一个libcurl选项,而是在PHP/curl绑定中提供的

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top