|
发表于 2020-3-3 23:21:50
|
显示全部楼层
本来我是不想回复的, 因为我会这样问你 表示我试过, 也知道是什么答案
但是看你帖子不多, 想着是才学python, 估计你测试的时候代码就没写对,
所以给你看下我的代码, 证明下我的答案。
- import requests
- proxies = {
- 'http':'http://123.123.123.123', # 这个代理地址是无效的
- 'https':'http://123.123.123.123', # 这个代理地址是无效的
- }
- url = 'http://www.baidu.com'
- try:
- r = requests.get(url, proxies=proxies)
- except Exception as e:
- print(f"error: {e}")
- else:
- print(r.status_code)
复制代码
## console output:
error: HTTPConnectionPool(host='123.123.123.123', port=80): Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000024EB51329D0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))) |
|