我有两个URL用于获取数据。使用我的代码,第一个URL可以正常工作,而第二个URL则会出现“代理错误(ProxyError)”。
我正在使用Python 3中的“requests”库,并尝试在Google和这里搜索问题,但都没有成功。
我的代码片段如下:
我正在使用Python 3中的“requests”库,并尝试在Google和这里搜索问题,但都没有成功。
我的代码片段如下:
import requests
proxies = {
'http': 'http://user:pass@xxx.xxx.xxx.xxx:xxxx',
'https': 'http://user:pass@xxx.xxx.xxx.xxx:xxxx',
}
url1 = 'https://en.oxforddictionaries.com/definition/act'
url2 = 'https://dictionary.cambridge.org/dictionary/english/act'
r1 = requests.get(url1, proxies=proxies)
r2 = requests.get(url2, proxies=proxies)
url1
没问题,但是 url2
显示以下错误:
ProxyError: HTTPSConnectionPool(host='dictionary.cambridge.org', port=443): Max retries exceeded with url: /dictionary/english/act (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response',)))
使用request.post()
也会发生同样的情况。
请解释一下为什么会出现这种情况,这两个URL之间的握手有什么区别吗?
urllib.request.urlopen
运行良好,所以我明确地寻求使用requests
来获取答案。