OWSLib icon indicating copy to clipboard operation
OWSLib copied to clipboard

Manage proxy for WMS request - WebMapService

Open armagaet opened this issue 7 years ago • 3 comments

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.

armagaet avatar Aug 23 '18 13:08 armagaet

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

ameier3 avatar Jun 21 '22 12:06 ameier3

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

Ok but how can I set these environment variable if the python code is launched from a browser?

armagaet avatar Nov 04 '22 13:11 armagaet

@armagaet

import os
address = # enter your proxy address
port = # the proxy port
os.environ["HTTP_PROXY"] = f"{address}:{port}"

tfardet avatar Jan 18 '23 14:01 tfardet