5๐
โ
Add following lines in your wsgi file.
import os
http_proxy = "10.10.1.10:3128"
https_proxy = "10.10.1.11:1080"
ftp_proxy = "10.10.1.10:3128"
proxyDict = {
"http" : http_proxy,
"https" : https_proxy,
"ftp" : ftp_proxy
}
os.environ["PROXIES"] = proxyDict
And Now you can use this environment variable anywhere you want,
r = requests.get(url, headers=headers, proxies=os.environ.get("PROXIES"))
P.S. โ You should have a look at following links
- Official Python Documentation for Environment Variables
- Where and how do I set an environmental variable using mod-wsgi and django?
- Python ENVIRONMENT variables
UPDATE 1
You can do something like following so that proxy settings are only being used on localhost
.
import socket
if socket.gethostname() == "localhost":
# do something only on local server, e.g. setting os.environ["PROXIES"]
os.environ["PROXIES"] = proxyDict
else:
# Set os.environ["PROXIES"] to an empty dictionary on other hosts
os.environ["PROXIES"] = {}
๐คpankaj28843
5๐
I got the same error reported by AmrFouad. At last, it fixed by updating wsgi.py as follows:
os.environ['http_proxy'] = "http://proxy.xxx:8080"
os.environ['https_proxy'] = "http://proxy.xxx:8080"
๐คTommy Tang
- [Django]-How to mark string for translation in jinja2 using trans blocks
- [Django]-Serving many on-the-fly generated images with Django
- [Django]-I have multiple django tables and want to query the tables in parallel
- [Django]-Why is my JSON from Django being cut-off at about 2.1MB?
Source:stackexchange.com