Search code examples
pythonproxypython-requestsproxy-server

How to use proxy in requests


I have got proxies from leafproxies, and they are giving me something like this. I don't really understand what this is. At the very end, I want to use it in requests.

Here's what they provide.

ipaddress:port:xxx:xxx

I believe that xxx:xxx part is username and password but I am not really sure.

Can anyone guide me, how can I use it with python requests?


Solution

  • You can try this :

    import requests
    import os
    
    #Syntax is http://username:password@ipaddress:port
    http_proxyf = 'http://xxx:[email protected]:8877'
    # Copy xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-au-xxxxxxxxxxxxxxxxx-xxxxxxxxxx:xxxxxxxxxxxx 
    # and paste at first 
     
    os.environ["http_proxy"] = http_proxyf
    os.environ["https_proxy"] = http_proxyf
    
    page=requests.get("https://google.com")
    

    To check you can do this:

    print(requests.get('https://api64.ipify.org?format=json').json())
    

    This will return the ip address.