Question

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

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.

Était-ce utile?

La solution

Le manuel montre l'utilisation étant quelque chose comme ceci :

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

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

Autres conseils

CURLOPT_RETURNTRANSFER est pas une option libcurl, il est fourni, mais au sein de la liaison PHP / CURL

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top