[Qgis-developer] http proxy support
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Fri Aug 15 13:10:34 EDT 2008
I can't get the python plugin installer to punch through our web proxy server.
There's code in Qgis to set a proxy host/port in the Options menu, but
this calls QNetworkProxy.setApplicationProxy(...) which seems to
concern itself with application-level proxying which I think is what
SOCKS is all about. This doesn't do HTTP proxying.
Here's my test python code (actually someone else's test code I modded):
import sys
from PyQt4.QtCore import *
from PyQt4.QtNetwork import QHttp, QNetworkProxy
def process(error):
if not error:
content = unicode(QString(page.readAll()))
print content
else:
print "errors occured"
print str(page.errorString())
quit()
if __name__ == "__main__":
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName("wwwcache.lancs.ac.uk")
proxy.setPort(8080)
QNetworkProxy.setApplicationProxy(proxy)
app = QCoreApplication (sys.argv)
page = QHttp(None)
#page.setProxy(proxy)
QObject.connect(page, SIGNAL("done(bool)"), process);
page.setHost('trolltech.com')
gprocId = page.get('/')
sys.exit (app.exec_ ())
- as written I get HTTP 403 Forbidden errors (as I do in Qgis). Using
Wireshark I see that the code is trying to connect to the host through
our proxy using HTTP's CONNECT method, which is probably how you set
up an application proxy tunnel. Our web proxy rejects it with a 403
and a short message.
If you uncomment the page.setProxy(proxy) line and comment out the
QNetworkProxy.setApplicationProxy(proxy) line then it all works for
me. I see a GET to the proxy with the correct URL for the remote host.
This seems to be the only way to do http proxying in Qt. Looks like
you have to set it for each QHttp transfer, which is not nice.
Digging around on the web finds some other examples of proxies being
set this way, but it's not something you can test unless you are
sitting behind a one. I have also considered it may be a problem in
PyQt4 - if anyone wants to translate my example to C++ so I can try it
here I'd like to see it.
Or possibly I'm just having a bad Friday..
Barry
More information about the Qgis-developer
mailing list