The Wayback Machine - https://web.archive.org/web/20210122054226/https://github.com/phuslu/requests_httpsproxy
Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.rst

requests-httpsproxy

allow http/https requests through HTTPS Proxy.

Requirements

  • requests >= 2.19.0
  • PyOpenSSL >= 0.11
  • tlslite-ng

Usage

The preferred way of using the library is importing and using the SecureProxySession. It has the exact same behavior as your usual requests.Session, but has secure HTTPS proxy support:

from requests_httpsproxy import SecureProxySession

https_proxy = 'https://username:password@host:port'

with SecureProxySession() as s:
  print (s.get('https://httpbin.org/ip', proxies={'http':https_proxy, 'https':https_proxy}).text)

In case you want to enable secure HTTPS proxy support project wise, you can patch the requests library:

import requests
from requests_httpsproxy import patch_requests
patch_requests()

https_proxy = 'https://username:password@host:port'
with requests.Session() as s:
  print (s.get('https://httpbin.org/ip', proxies={'http':https_proxy, 'https':https_proxy}).text)

Keep in mind, that enabling the secure HTTPS proxy breaks the behavior of regular HTTPS proxies. If you want to use both, use the SecureProxySession for secure proxies and requests.Session for the regular HTTPS proxies.

An other solution would be to always use the patch or SecureProxySession, but set verify = False, which disables verifying the SSL certificate:

from requests_httpsproxy import SecureProxySession

https_proxy = 'https://username:password@host:port'

with SecureProxySession() as s:
  s.verify = False
  print (s.get('https://httpbin.org/ip', proxies={'http':https_proxy, 'https':https_proxy}).text)

Common issues

If the proxy credentials contain symbols, that can't be present in a url (causing a parse error), try encoding them with quote_plus:

import urllib.parse
from requests_httpsproxy import SecureProxySession

username_encoded = urllib.parse.quote_plus(username)
password_encoded = urllib.parse.quote_plus(password)

https_proxy = 'https://{}:{}@host:port'.format(username_encoded, password_encoded)

with SecureProxySession() as s:
  s.verify = False
  print (s.get('https://httpbin.org/ip', proxies={'http':https_proxy, 'https':https_proxy}).text)

License

MIT

Related issues

About

allow http/https requests through https proxy

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages