Django set a connection proxy

0

I have long time seeking for a solution to set a proxy for my Django application.

1st I am using Django==2.0 and I run it in Windows Server 2016 in a local network that uses a Proxy to connect 10.37.235.99 and Port 80. and I’m deploying the application using nginx-1.20.1

I have to scrape a data as

    http_proxy  = "10.37.235.99:80"
    https_proxy = "10.37.235.99:80"
    ftp_proxy   = "10.37.235.99:80"

    proxyDict = { 
                  "http"  : http_proxy, 
                  "https" : https_proxy, 
                  "ftp"   : ftp_proxy
                }
    import socket
    if socket.gethostname() == "localhost":
        os.environ["PROXIES"] = proxyDict
    else:
        os.environ["PROXIES"] = {}
    URL='my_site.com'
    page = requests.get(URL)
    print(page)

I tried many solutions on the internet but no way! Working with django : Proxy setup

when I remove the proxy configuration and I use Psiphon3(with proxy) everything works perfectly.

is there any solution?

It looks like you’re talking about a situation where you need to make an outbound connection through a proxy, not set up a proxy connection to allow for inbound requests, is that correct?

If so, then this isn’t a Django issue. No configuration changes to Django should be needed. It does not look like you’re using Django to retrieve data from that external site.

Your Python code to make that external request should work exactly the same way regardless of whether its running in Django or not.

Having said that, most Windows proxies can create real problems, because many of them require the outbound request to be ActiveDirectory authenticated.

1 Like