Python/cURL

Aus SchnallIchNet
Wechseln zu: Navigation, Suche

pycurl (cURL for python)

import pycurl
import StringIO

b = StringIO.StringIO()

c = pycurl.Curl()
c.setopt(pycurl.URL, "http://www.python.org/")
c.setopt(pycurl.HTTPHEADER, ["Accept:"])
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.perform()

print b.getvalue()
print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL)


urlencode

perhaps you will need url-encoding for curl:

import urllib
f = { 'eventName' : 'myEvent', 'eventDescription' : "cool event"}
urllib.urlencode(f)

or simply use:

urllib.urlencode( {'eventName' : 'myEvent', 'eventDescription' : "cool event"} )

Output:

eventName=myEvent&eventDescription=cool+event