[QGIS-Developer] Proxy configuration in plugin

Sampo Savolainen sampo.savolainen at spatineo.com
Fri Jan 22 00:14:13 PST 2021


Hi,

Thanks for the responses. We'll look into using QgsNetworkAccessManager.
Hopefully integrating owslib and QgsNetworkAccessManager isn't too
inconvenient.

As pointed out, proxy setup is never transparent whatever the IT department
thinks. I have one suggestion for QGIS: as most people dealing with proxies
know, http_proxy and https_proxy environment variables are pretty much the
standard way to set proxies in Linux as well as Mac and Windows. As such,
it would make sense if QGIS would ensure that these variables are set in
the environment where python plugins are executed. While the mapping
between more dynamic proxy configurations and these environment variables
are not one-to-one in all cases, even a simplified setting would push
things to the right direction. This would probably fix proxy issues in
existing plugins (not just the one I'm working on).


 Sampo

On Thu, Jan 21, 2021 at 11:22 AM Etienne Trimaille <
etienne.trimaille at gmail.com> wrote:

> The proxy settings are only set up for core class in QGIS, which you
> should look at to make your requests.
> CF
> https://gis.stackexchange.com/questions/343126/how-to-perform-sync-or-async-network-request-in-pyqgis
>
> If you really want to use "requests", you should read the QgsSettings
> about proxy and use these values in requests as well.
> Similar to
> https://stackoverflow.com/questions/23041066/setting-proxy-parameter-in-qgis-plugins-how-to/37757921#37757921
>
> Le jeu. 21 janv. 2021 à 15:03, Sampo Savolainen <
> sampo.savolainen at spatineo.com> a écrit :
>
>> Hi,
>>
>> I'm developing a small QGIS plugin (
>> https://github.com/spatineo/qgis-intelligent-search/) and ran into
>> issues with proxy configuration. The plugin uses the Python requests
>> library to make HTTP API calls and owslib to download and parse
>> GetCapabilities documents from WxS services. Owslib seems to use the same
>> requests library to make HTTP calls. However proxies are (unsurprisingly)
>> giving us headaches.
>>
>> We have tested the plugin in two environments where proxies are required
>> to make HTTP requests. The environments had different versions of QGIS:
>> 3.14 and 3.10, both in Windows. The first environment (newer version) is
>> able to make the API calls using the requests library, but owslib fails to
>> connect to services. The older version of QGIS fails to connect to the API
>> and the owslib part never gets tested. Note that this discrepancy may be
>> related to the API being available without a proxy in the first
>> environment  - though this is just a suspicion, I have been unable to
>> confirm this.
>>
>> With 3.10, I've tried QGIS proxy configuration both as "DefaultProxy"
>> (use system config) and as "HttpProxy" but neither one helped. However I
>> was able to make it work by setting the http_proxy and https_proxy
>> environment variables in a shell and launching QGIS from that shell.
>>
>> So this seems to boil down to the QGIS proxy settings are not passed to
>> the plugin via http_proxy and https_proxy environment variables. Is there a
>> best practice on how plugins should access proxy configuration in QGIS and
>> use it?
>>
>>
>>  Thanks,
>>  Sampo
>>
>> --
>> Sampo Savolainen
>> Managing Director
>> Työpajankatu 9 D, 00580 Helsinki, Finland
>> www.spatineo.com
>> Tel. +358 40 7555 649
>>
>>
>>
>> This message may contain privileged and/or confidential information. If
>> you have received this e-mail in error or are not the intended recipient,
>> you may not use, copy, disseminate, or distribute it; do not open
>> any attachments, delete it immediately from your system and notify the
>> sender promptly by e-mail that you have done so.
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>

-- 
Sampo Savolainen
Managing Director
Työpajankatu 9 D, 00580 Helsinki, Finland
www.spatineo.com
Tel. +358 40 7555 649



This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient,
you may not use, copy, disseminate, or distribute it; do not open
any attachments, delete it immediately from your system and notify the
sender promptly by e-mail that you have done so.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210122/af732578/attachment.html>


More information about the QGIS-Developer mailing list