Website hosting service by

 Back to Index

11.5.20 Examples

This example gets the main page and displays the first 100 bytes of it:

>>> import urllib2
>>> f = urllib2.urlopen('')
>>> print
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?xml-stylesheet href="./css/ht2html

Here we are sending a data-stream to the stdin of a CGI and reading the data it returns to us:

>>> import urllib2
>>> req = urllib2.Request(url='https://localhost/cgi-bin/test.cgi',
...                       data='This data is passed to stdin of the CGI')
>>> f = urllib2.urlopen(req)
>>> print
Got Data: "This data is passed to stdin of the CGI"

The code for the sample CGI used in the above example is:

#!/usr/bin/env python
import sys
data =
print 'Content-type: text-plain\n\nGot Data: "%s"' %




2002-2004 Webhosting Service


Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to


Cheap domain registration : Register domain name or buy domain name, including free domain hosting services offers cheap domain registration, domain name transfer and domain search services    

Domain registration : Buy domain name or register domain name from $5.95/year only