Jon*_*ior 8 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)
Run Code Online (Sandbox Code Playgroud)
并执行脚本,它失败了.
File "getdata.py", line 46, in apicall
ocurl.setopt(pycurl.RETURNTRANSFER, 1)
AttributeError: 'module' object has no attribute 'RETURNTRANSFER'
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么,以及为什么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 "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>
Run Code Online (Sandbox Code Playgroud)
似乎有点迂回,但我不是PycURL的忠实粉丝......
| 归档时间: |
|
| 查看次数: |
4520 次 |
| 最近记录: |