[QGIS-Developer] Proxy support in Python Plugins

Nils Nolde nilsnolde at gmail.com
Sat Mar 30 09:33:12 PDT 2019


Hi,

I want to upgrade ORS Tools to not work with requests anymore to fetch 
GET and POST queries. However, I never used QgsNetworkAccessManager and 
have little knowledge about networking in general. I tried mostly 
Boundless Geo's NetworkAccessManager wrapper. Couldn't make it work for 
my plugin. When I set a free online Proxy in QGIS settings, all other 
apps/plugin in QGIS could access the internet, my plugin couldn't, it 
would timeout.

I did smth akin to:

nam = networkaccessmanager.NetworkAccessManager()

base_url = 'https://nominatim.openstreetmap.org/reverse'
params = {'lat': point.y(), 'lon': point.x(), 'format': 'json'}
url = base_url + '?' + urlencode(params)

response, content = self.nam.request(url=url, headers={'User-Agent': 
user_agent}, blocking=False)

Figuring it would automatically use the Proxy settings in QGIS. It 
doesn't, it seems. So 3 questions:

1. How do I make my code use the QGIS proxy settings?

2. How do I debug, i.e. how do I check that the request actually used 
the proxy settings? Couldn't find much, even on the native Qt parent.

3. Is there a way to use non-blocking requests in native 
QgsNetworkAccessManager? Actually it's not so important, since batch 
requests are being done within the Processing framework (assuming that 
won't affect the main thread..), it's more informational.

I did some research, but as I don't find a terrible amount of time 
lately to maintain all the open source projects, I was hoping to get 
some quick answer from someone. I'm sure I'm missing smth really 
obvious. Sorry, if it really is obvious and I just can't see it.. Also, 
a reference to an existing plugin would suffice.

Many thanks
Nils



More information about the QGIS-Developer mailing list