Over a million developers have joined DZone.

GET Stream From The Web Using Python

·
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()
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}