使用python requests模塊調用vmallarg.vmall.com接口API時報如下錯誤:
requests.exceptions.ConnectionError:
HTTPSConnectionPool(host='vmallrag.vmall.com', port=443): Max retries exceeded with url: .... (Caused by New ConnectionError('ect at 0x01C3DA10>: Failed to establish a new connection:
[Errno 10060] ',))
測試場景:
在postman中調用時可以成功返回,在瀏覽器中也可以成功訪問該網址。
然而在dos下telnet連接失敗:

這是為什么呢?原來在公司內網設置了瀏覽器代理服務器,想訪問外部網址必須經過代理服務器才能訪問,公司代理服務器地址:xx.aa.com 端口:8080(這個代理在IE設置局域網中可以看到)
所以在requests中設置對應的代理就能連接正常了,代理設置如下:
https的請求代理:proxy = {"https":"xx.aa.com:8080"},http的請求代理: proxy = {"http":"xx.aa.com:8080"},或者http/https的一並設置:proxy={"https":"xx.aa.com:8080","http":"xx.aa.com:8080"}
然后在requests的get、post方法中指定如下:
requests.get(url, proxies=proxy)
requests.post(url, proxies=proxy)