Debian Codegraph @

examples/quickstart/get.py

raw
1 #! /usr/bin/env python
2 # vi:ts=4:et
3
4 import pycurl
5 from io import BytesIO
6
7 buffer = BytesIO()
8 c = pycurl.Curl()
9 c.setopt(c.URL, 'http://pycurl.io/')
10 c.setopt(c.WRITEDATA, buffer)
11 # For older PycURL versions:
12 #c.setopt(c.WRITEFUNCTION, buffer.write)
13 c.perform()
14 c.close()
15
16 body = buffer.getvalue()
17 # Body is a byte string.
18 # If we know the encoding, we can always decode the body and
19 # end up with a Unicode string.
20 print(body.decode('iso-8859-1'))