Domanda

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

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 idea di cosa sta succedendo, e perché RETURNTRANSFER non sembra esistere, mentre tutte le altre opzioni fanno.

È stato utile?

Soluzione

Il manuale mostra l'utilizzo di essere qualcosa di simile :

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

Altri suggerimenti

CURLOPT_RETURNTRANSFER non è un'opzione libcurl, ma è fornita entro vincolante PHP / CURL

Hai provato esecuzione print dir(pycurl) e vedere se l'opzione presente nella lista di attributi?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top