Skip to content Skip to sidebar Skip to footer

Python Requests Doesnt Work For Https Proxy

I try to use https proxy in python like this: proxiesDict ={ 'http': 'http://' + proxy_line, 'https': 'https://' + proxy_line } response = requests.get('https://api.ipify.or

Solution 1:

When specifying a proxy list for requests, the key is the protocol, and the value is the domain/ip. You don't need to specify http:// or https:// again, for the actual value.

So, your proxiesDict will be:

proxiesDict = {
  'http':  proxy_line,
  'https': proxy_line
}

Solution 2:

You can also configure proxies by setting the enviroment variables:

$ export HTTP_PROXY="http://proxyIP:PORT"$ export HTTPS_PROXY="http://proxyIP:PORT"

Then, you only need to execute your python script without proxy request.

Also, you can configure your proxy with http://user:password@host

For more information see this documentation: http://docs.python-requests.org/en/master/user/advanced/

Solution 3:

Try using pycurl this function may help:

import pycurl

defpycurl_downloader(url, proxy_url, proxy_usr):
    """
    Download files with pycurl
    the proxy configuration:
    proxy_url = 'http://10.0.0.0:3128'
    proxy_usr = 'user:password'
    """

    c = pycurl.Curl()
    c.setopt(pycurl.FOLLOWLOCATION, 1)
    c.setopt(pycurl.MAXREDIRS, 5)
    c.setopt(pycurl.CONNECTTIMEOUT, 30)
    c.setopt(pycurl.AUTOREFERER, 1)

    if proxy_url: c.setopt(pycurl.PROXY, proxy_url)
    if proxy_usr: c.setopt(pycurl.PROXYUSERPWD, proxy_usr)

    content = StringIO()
    c.setopt(pycurl.URL, url)
    c.setopt(c.WRITEFUNCTION, content.write)

    try:
        c.perform()
        c.close()
    except pycurl.error, error:
        errno, errstr = error
        print'An error occurred: ', errstr

    return content.getvalue()

Post a Comment for "Python Requests Doesnt Work For Https Proxy"