Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

28 Commits

Repository files navigation

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:

fromrequests_httpsproxyimportSecureProxySessionhttps_proxy='https://username:password@host:port'withSecureProxySession() ass:
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:

importrequestsfromrequests_httpsproxyimportpatch_requestspatch_requests()
https_proxy='https://username:password@host:port'withrequests.Session() ass:
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:

fromrequests_httpsproxyimportSecureProxySessionhttps_proxy='https://username:password@host:port'withSecureProxySession() ass:
s.verify=Falseprint (s.get('https://httpbin.org/ip', proxies={'http':https_proxy, 'https':https_proxy}).text)

In case you don't want to verify the secure proxy's SSL certificate (for example, when making requests using proxy IP), you can disable the verification by passing insecure_requests=True:

fromrequests_httpsproxyimportSecureProxySessionhttps_proxy='https://username:password@host:port'withSecureProxySession(insecure_requests=True) ass:
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:

importurllib.parsefromrequests_httpsproxyimportSecureProxySessionusername_encoded=urllib.parse.quote_plus(username)
password_encoded=urllib.parse.quote_plus(password)
https_proxy='https://{}:{}@host:port'.format(username_encoded, password_encoded)
withSecureProxySession() ass:
s.verify=Falseprint (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

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages