pycurl:RETURNTRANSFER选项不存在

发布于 2024-07-20 05:34:15 字数 582 浏览 6 评论 0原文

我正在使用 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 似乎不存在,而所有其他选项都存在。

I'm using pycurl to access a JSON web API, but when I try to use the following:

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)

and execute the script, it fails.

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

I haven't a clue what's going on, and why RETURNTRANSFER doesn't appear to exist while all the other options do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

再可℃爱ぅ一点好了 2024-07-27 05:34:15

该手册显示的用法是类似这样的

>>> 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 "example.com",
"example.net",
  or "example.org" 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 的忠实粉丝...

The manual shows the usage being 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 "example.com",
"example.net",
  or "example.org" 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>

Seems a little roundabout, but I'm not a big fan of PycURL...

顾挽 2024-07-27 05:34:15

CURLOPT_RETURNTRANSFER 不是 libcurl 选项,它是在 PHP/CURL 绑定中提供的

CURLOPT_RETURNTRANSFER is not a libcurl option, it is but provided within the PHP/CURL binding

屋檐 2024-07-27 05:34:15

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

Have you tried executing print dir(pycurl) and see if the option exists in the attribute list?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文