Python 3.4 using urlopen to get web content via proxy

青春壹個敷衍的年華 提交于 2019-12-24 16:39:05

问题


Using the example below i am trying to get web conents from behind a proxy server but so far am unsuccessful.

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 am going wrong? If I remove the proxies argument I get:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

If I enter proxies argument I get:

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

Am using PyCharm as the IDE and if I check internet connection from within the PyCharm settings, it succeeds.

Thanks for any suggestion.

来源:https://stackoverflow.com/questions/29850153/python-3-4-using-urlopen-to-get-web-content-via-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!