python - pycurl: RETURNTRANSFER 选项不存在

标签 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 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 似乎不存在,而所有其他选项都存在。

最佳答案

手册显示用法为something like this :

>>> 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 的忠实粉丝......

关于python - pycurl: RETURNTRANSFER 选项不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/872844/

相关文章:

python - 使用 Python 或 Curl 获取页面时出现不同的页面

c++ - 静态库已链接但仍 undefined reference

python - 溢出错误: size does not fit in an int

Python - 查找 unicode/ascii 问题

python - 根据键重新排列列表而不排序

PHP Curl - 以下位置带有 "201 Created"响应头

git - 在 git-clone 期间使用主动模式 FTP 而不是被动模式?

libcurl - 为 curl_easy_setopt 函数定义的 CURLOPT_* 常量在哪里?

c++ - 使用 C++/libcurl/openssl 的应用程序安全服务器通信

python - 在 python 3.9 中从 requirements.txt 安装包时出错