OWSLib
OWSLib copied to clipboard
Manage proxy for WMS request - WebMapService
Sorry I'm not really at ease to the use of github. Anyway, for my purpose I've found useful to define a proxy in the WMS url request. I've modified, locally on my code, the req definition inside the "openURL" function, here:
"/usr/lib/python2.6/site-packages/owslib/util.py"
As this:
#at the beginning:
proxies = None
from config import * #here I've set my proxies variable as
'''
proxies = {
"http": "http://ip:port",
"https": "https://ip:port",
}
'''
#...and then, inside the openURL function...
req = requests.request(method.upper(),
url_base,
headers=headers,
proxies=proxies,
**rkwargs)
Hope to have been useful to someone, or maybe you have coded a better solution. This was fast and furious...
A.R.
It is not necessary to modify the code!
requests honors the environment variables HTTP_PROXY and HTTPS_PROXY. If set, these will be used automatically , see https://requests.readthedocs.io/en/latest/user/advanced/?highlight=proxies#proxies
It is not necessary to modify the code!
requestshonors the environment variablesHTTP_PROXYandHTTPS_PROXY. If set, these will be used automatically , see https://requests.readthedocs.io/en/latest/user/advanced/?highlight=proxies#proxies
Ok but how can I set these environment variable if the python code is launched from a browser?
@armagaet
import os
address = # enter your proxy address
port = # the proxy port
os.environ["HTTP_PROXY"] = f"{address}:{port}"