2017-02-09 111 views
1

我正在使用python請求來使用https代理加載頁面,但它不工作。相同的代碼與http代理一起工作。與https代理請求

以下是我的代碼:

以HTTPS代理

import requests 
proxyDict = {'https': 'https://xxx.xxx.xxx.xxx:xx'} 
r = requests.get('http://icanhazip.com', proxies=proxyDict) 
print(r) 
print(r.content) 

輸出:

響應[200]

xxx.xxx.xxx.xxx - 該IP是爲我的服務器而不是代理服務器

使用HTTP代理

import requests 
proxyDict = {'http': 'http://xxx.xxx.xxx.xxx:xx'} 
r = requests.get('http://icanhazip.com', proxies=proxyDict) 
print(r) 
print(r.content) 

輸出:

響應[200]

xxx.xxx.xxx.xxx - 該IP是代理服務器

如何使用https代理服務器與python請求

我的代碼中是否有錯誤?或者如何解決這個問題?

請幫我解決這個問題。

回答

1

在您的第一個代碼示例中,您正在使用HTTPS代理,但向HTTP站點發出請求。您應該改爲r = requests.get('https://icanhazip.com', proxies=proxyDict)

+0

雅這就是我昨天測試後也想到的。感謝@Rytis的幫助 –