Pycurl:returnTransferオプションは存在しません
-
22-08-2019 - |
質問
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 "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の大ファンではありません...
他のヒント
curlopt_returntransferはlibcurlオプションではありません。これはPHP/Curlバインディング内で提供されます。
実行してみましたか print dir(pycurl)
そして、オプションが属性リストに存在するかどうかを確認しますか?
所属していません StackOverflow