DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

prasanna has posted 1 posts at DZone. View Full User Profile

GET Stream From The Web Using Python

07.03.2008
| 6778 views |
  • submit to reddit
        GETs files from a remote webserver. I'm using it for streaming
def get(host,port,url):
    h = httplib.HTTP(host, port)
    h.putrequest('GET', url)
    h.putheader('Host', host)
    h.putheader('User-agent', 'python-httplib')
    h.endheaders()

    (returncode, returnmsg, headers) = h.getreply()
    if returncode != 200:
        print returncode, returnmsg
        sys.exit()

    f = h.getfile()
    return f.read()