2009-05-16 8 views
8

sto usando pycurl per accedere a un Web API JSON, ma quando cerco di utilizzare il seguente:pycurl: opzione RETURNTRANSFER non esiste

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) 

ed eseguire lo script, non riesce.

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

non ho la minima idea di cosa sta succedendo, e perché RETURNTRANSFER non sembra esistere, mentre tutte le altre opzioni fanno.

risposta

7

Il manuale mostra l'utilizzo essendo 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> 

sembra un po 'rotonda, ma io non sono un grande fan di pycurl ...

+0

Sì, funziona perfettamente. Mi chiedo perché non dovrebbero solo implementare RETURNTRANSFER per iniziare. –

0

Hai provato a eseguire print dir(pycurl) e verificare se l'opzione esiste nell'elenco degli attributi?

5

CURLOPT_RETURNTRANSFER non è un'opzione libcurl, è ma fornito all'interno del PHP/CURL binding

Problemi correlati