使用具有身份验证和https的代理

时间:2016-09-16 09:54:54

标签: python-3.x curl proxy

我使用curl通过代理连接到https网页,具体来说就是这个命令:

curl --proxy https://PROXY_IP:80 -PROXY_USERNAME:PROXY_PASSWORD -k -L https://www.rotogrinders.com

你知道如何在Python 3中做同样的事情吗?我尝试了请求库,但它没有用,可能是因为https通过代理在请求中被窃听。

编辑:请求代码:

import requests
from requests.auth import HTTPProxyAuth

class Downloader:
    def get_page(self, url):
        proxies = self.get_proxies()
        auth = HTTPProxyAuth("PROXY_USERNAME", "PROXY_PASSWORD")

        r = requests.get(url, proxies = proxies, auth = auth)
        return r.text

    def get_proxies(self):
        return {"https" : "PROXY_IP:80"}


downloader = Downloader()
downloader.get_page("https://www.rotogrinders.com")    

此代码返回以下异常: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.rotogrinders.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

0 个答案:

没有答案
相关问题