8

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 が存在しないように見えるのか、私にはわかりません。

4

3 に答える 3

7

マニュアルには、次のような使用法が示されています。

>>> 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 の大ファンではありません...

于 2009-05-16T17:39:01.940 に答える
5

CURLOPT_RETURNTRANSFERはlibcurlオプションではなく、PHP/CURLバインディング内で提供されます。

于 2009-05-16T20:18:55.613 に答える
0

実行print dir(pycurl)して、オプションが属性リストに存在するかどうかを確認しましたか?

于 2009-05-16T17:32:18.977 に答える