stac-utils / qgis-stac-plugin

QGIS plugin for reading STAC APIs
GNU General Public License v3.0
67 stars 21 forks source link

Connect to service when behind a proxy #230

Open lglnlf opened 1 year ago

lglnlf commented 1 year ago

Version 1.1.1 on QGIS 3.22.8 It is not possible to connect to services when behind my organizations proxy. The code revealed that proxy settings are not included in the requests at the moment. Is that correct? Anyway, in my case the change of some requests in the code helped to connect to the services with a proxy.

For requests from _pystacclient I changed the requests to the following form:

from pystac_client.stac_api_io import StacApiIO
...
proxy_dict = {"https": "<PROXY_ADDRESS>:<PORT>"}
stac_api_io = StacApiIO()
stac_api_io.session.proxies = proxy_dict 
client = Client.from_file(url, stac_io=stac_api_io)

And for requests with Pythons requests lib by adding the proxy dictionary directly as an argument:

response = requests.get(url, headers=headers, proxies=proxy_dict)

As a suggestion for the plugin development it would be good to use the QGIS global proxy settings from QSettings for the plugins requests. You can easily access them by their values:

settings = QSettings()
proxy_host = settings.value('proxy/proxyHost')
proxy_port = settings.value('proxy/proxyPort')
proxy_enabled = settings.value('proxy/proxyEnabled')

And apart from that it could also be useful to have some proxy config in the UI of the plugin.

Besides I have no clue about my organisations proxy. Maybe it should all workout automatically without further configuration, because it usually does that when using web browsers e.g..

ameier3 commented 2 months ago

+1 for the support of proxy settings. Without this feature the plug-in is practically useless within my organization.

I have tried setting the environment variables. However,this didn't have any effect.