简体   繁体   中英

Can't use proxies with python

So I'm simply writing a script to test out the proxies in python, but I can't get it to work. I always get a Proxy Error

The very simple code:

import requests

def normal():
    response = requests.get('https://www.google.com/',
                       proxies={
                           'http': 'http://myUserNameUrlEncoded:myPasswordEncoded@uk2049.nordvpn.com',
                           'https': 'http://myUserNameUrlEncoded:myPasswordEnco@uk2049.nordvpn.com',
                       }
                       )
    print(response)

The error I get is the following:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f6d123be640>: Failed to establish a new connection: [Errno 110] Connection timed out')))

First thing I notice... why is the host being taken as www.google.com ? This seems to be random when it does this, and when the host is successfully set to uk2049.nordvpn.com it still times out. (I've already tried increasing the timeout).

Any help is appreciated. Thanks!

EDIT I figured out the problemm is only with https proxies. For some reason, python is taking the host to be the url I'm sending.

Long overdue answer, turns out the requests module doesn't handle https proxies. To take advantage of this, use pycurl ♂️

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM