2009-05-16 6 views
8

J'utilise pycurl pour accéder à une API Web JSON, mais lorsque je tente d'utiliser ce qui suit:pycurl: l'option RETURNTRANSFER n'existe pas

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) 

et exécuter le script, il échoue.

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

Je n'ai pas la moindre idée de ce qui se passe, et pourquoi RETURNTRANSFER ne semble pas exister alors que toutes les autres options font.

Répondre

7

Le manuel montre l'utilisation étant 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> 

un petit rond-point Semble, mais je ne suis pas un grand fan de pycurl ...

+0

Oui, cela fonctionne très bien. Je me demande pourquoi ils n'utiliseraient pas simplement RETURNTRANSFER pour commencer. –

0

Avez-vous essayé d'exécuter print dir(pycurl) et de voir si l'option existe dans la liste d'attributs?

5

CURLOPT_RETURNTRANSFER est pas une option libcurl, il est mais fourni dans la liaison PHP/CURL

Questions connexes