Is it possible to set a proxy chain with Python's requests library?

You can implement your logic at the code level. The HTTP_PROXY environment variable is not the only way to specify the proxy. Use a proxies parameter just like it says the documentation

import requests

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

requests.get('http://example.org', proxies=proxies)

So you can handle these exceptions (I mean ProxyError), and in case change the proxies within the param


I think proxy chaining is not possible. If it's possible then give us some working code. I have tried this but, later I understood that it's silly. But still I am losing it, when I see how proxychains terminal app work.

My code:

import socket

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('182.52.22.58', 8080))
   ''' s.connect(('61.7.128.94' , 8080))'''
    request = b"CONNECT 146.88.51.238:80 HTTP/1.1\n\n"
    s.send(request)
    print('hi' + s.recv(4096).decode())
    request = b"GET google.com HTTP/1.1\n\n"
    s.send(request)
    print(s.recv(4096).decode())

main()