Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pycurl: RETURNTRANSFER option doesn't exist

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.

like image 234
Jonathan Prior Avatar asked May 16 '09 17:05

Jonathan Prior


2 Answers

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 &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>

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

like image 165
Paolo Bergantino Avatar answered Oct 27 '22 16:10

Paolo Bergantino


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

like image 35
Daniel Stenberg Avatar answered Oct 27 '22 16:10

Daniel Stenberg