Python 3.4 using urlopen to get web content via proxy

Using the example below, I am trying to get web connections from a proxy server, but have not yet succeeded.

proxies = {'http': 'http://proxy:8080'}
from urllib.request import urlopen
with urlopen('http://sixty-north.com/c/t.txt', proxies) as story:
    story_words = []
    for line in story:
        line_words = line.split()
        for word in line_words:
            story_words.append(word)

story_words

Any idea where I'm wrong? If I remove the proxies argument, I get:

[WinError 10060] Connection attempt failed because the connected side did not respond properly after a certain period of time or the connection failed because the connected host was unable to respond

If I enter a proxy argument, I get:

ValueError: Content-Length should be specified for duplicate data type {'http': ' http: // proxy: 8080 '}

I use PyCharm as an IDE, and if I check the Internet connection in PyCharm settings, it will succeed.

.

+1

All Articles