Hugh Chalmers Hugh Chalmers - 4 days ago 4
Python Question

Read text file over internet on python

Here's a text file on the internet (http) http://hughchalmers.com/example.txt. How would I print that in Python 2?

People are saying this is a duplicate, I would like to say that it is not a duplicate, any other script I found gave Error 412.

wim wim
Answer
>>> from urllib2 import Request, urlopen
>>> url = 'http://hughchalmers.com/example.txt'
>>> urlopen(Request(url=url, headers={'User-Agent': "hey, it's wim"})).read()
'Exmaple Text'
Comments