Python/cURL: Unterschied zwischen den Versionen
Aus SchnallIchNet
< Python
Cbs (Diskussion | Beiträge) |
Cbs (Diskussion | Beiträge) |
||
Zeile 16: | Zeile 16: | ||
print b.getvalue() | print b.getvalue() | ||
print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL) | 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 |
Aktuelle Version vom 11. August 2011, 07:36 Uhr
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