[QGIS-Developer] Proxy configuration in plugin

Richard Duivenvoorde rdmailings at duif.net
Thu Jan 21 01:18:21 PST 2021


On 1/21/21 9:02 AM, Sampo Savolainen wrote:
> 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?

Hi Sampo,

In mij experience, it IS possible to use Requests/Urllib for you requests and let them find the proxy... But it is hard and there are just to many options/setups/os's etc etc

BUT in general I would recommend: use QGIS' own QgsNetworkAccessManager requests [0], then you:
- will just use the proxy settings from QGIS itself (in which case I often use 'default' proxy in Windows environments, and then (Qt) picks those up)
- you will be able to debug the requests in the QGIS debug part (F12) in recent QGIS (or via the QGIS Network Logger plugin for older version).

If you need simple 'fire and get' requests, just use the blockingGet or blockingPost ones. If you need more complex setups, you have to create your own (QgsNetworkAccessManager is a wrapper around Qt's QNetworkAccessManager, so read up about this here: [1])

But: proxies stay hard (and never as 'transparant' as sysadmins try you to tell)

Regards,

Richard Duivenvoorde

[0] https://qgis.org/pyqgis/3.16/core/QgsNetworkAccessManager.html
[1] https://doc.qt.io/qt-5/qnetworkaccessmanager.html





More information about the QGIS-Developer mailing list