The backend of my site is located on a server with an IP address of Germany, but I need to send requests to other services as if I were in Ukraine. I mean that you can buy a proxy from this country and work through it somehow, but I don’t know how to implement it. Ideally, I would like to globally change the address so that all application requests are sent from it by default, but at the same time the backend itself is available as before at the address that the hosting gave me.

Here are the technologies I'm using:

  • python
  • django
  • nginx
  • dokku

Python has an excellent library requests, which partially answers my question, but I would not like to add a proxy to every request. Perhaps this can be globally applied to a django project?

import requests
from requests.auth import HTTPProxyAuth
url= 'http://google.com/'
proxies= {'http': ''}
auth= HTTPProxyAuth ('my_login', 'my_password')
response= requests.get (url= url, proxies= proxies, auth= auth)
response.close ()
print (response.status_code) # 200 -good

through requests you can just proxies= {'http': 'user: password @ ip: port'}

Jack_oS2021-02-23 22:16:01

You can try to set a proxy through session for requests and use the session object everywhere

gil9red2021-02-23 22:16:01

I would raise something like anonymous end-to-end 3Proxy on a dedicated server with a ukrian ip

Jack_oS2021-02-23 22:16:01

@Jack_oS Did I understand correctly, this is put right on the server next to the same nginx and in fact my address changes to the proxy that I connect? if so, then my site will now be available at the Ukrainian address.

Eduard Kumskyi2021-02-23 22:16:01

no, it must be on a server in Ukraine: make a request from your backend through this proxy to other services, they will see requests with a Ukrainian ip

Jack_oS2021-02-23 22:16:01
  • Answer # 1

    Set proxy for requestsusing a dictionary like {'http': 'http: //user: pass @ address: port'} :

    import requests
    login= 'my_login'
    password= 'my_password'
    address= ''
    port= '3128'
    proxies= {
        'http': f'http: //{login}: {password} @ {address}: {port} ',
        'https': f'https: //{login}: {password} @ {address}: {port}',

    and check the performance with some service

    url= 'https://ifconfig.me/all.json'

    which in response to your

    r= requests.get (url= url, proxies= proxies)
     json.loads (r.content)

    will return, among other things, the ip from which the request came:

        'ip_addr': '',
        'remote_host': 'unavailable',
        'user_agent': 'python-requests /2.24.0',
        'port': 55952,
        'method': 'GET',
        'encoding': 'gzip, deflate', 'mime':
        '* /*',
        'via': '1.1 google',
        'forwarded': ','