geopython / OWSLib

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.
https://owslib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
381 stars 273 forks source link

Manage proxy for WMS request - WebMapService #512

Open armagaet opened 6 years ago

armagaet commented 6 years ago

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.

ameier3 commented 2 years ago

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

armagaet commented 1 year ago

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?

tfardet commented 1 year ago

@armagaet

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