5

This is driving me crazy.

I want to show in a QWebPage an url, but i want to do it passing by an anonimous proxy.

Code

#setting up the proxy

proxy = QNetworkProxy()
proxy.setHostName("189.75.98.199") #just examples
proxy.setPort(1111)
proxy.setType = QNetworkProxy.HttpProxy

#setting the manager

manager = QNetworkAccessManager()
manager.setProxy(proxy) #setting the proxy on the manager

#setting the proxy as application proxy

QNetworkProxy.setApplicationProxy(proxy) #seems to do nothing..

#web page

webpage = QWebPage()
webpage.setNetworkAccessManager(manager) #maybe.. but it doesn't work

webpage.mainFrame().load(QUrl("http://www.foo.bar") )

I call a test page which tells me the headers (on a php server, so i look at $_SERVER), and remote_addr is always my ip, not the proxy ip.

What's wrong?

Can you help me? I'm using PyQt 4.8.3.

apelliciari
  • 8,241
  • 9
  • 57
  • 92

1 Answers1

4

got it to work

in this way it works, using setApplicationProxy. I still don't understand why setting proxy parameters after instance creation doesn't work (as in the initial example)

def set_proxy(self,  proxy):

    proxy_url = QUrl(proxy)

    if unicode(proxy_url.scheme()).startswith('http'):
        protocol = QNetworkProxy.HttpProxy
    else:
        protocol = QNetworkProxy.Socks5Proxy
    QNetworkProxy.setApplicationProxy(
        QNetworkProxy(
            protocol,
            proxy_url.host(),
            proxy_url.port(),
            proxy_url.userName(),
            proxy_url.password()))
apelliciari
  • 8,241
  • 9
  • 57
  • 92
  • and how to unset proxy or just keep request handlers with proxy support and without proxy support? – sultan May 27 '11 at 14:26
  • There is QNetworkProxy.NoProxy type which you need to use instead of HttpProxy or Socks5Proxy – varela Sep 27 '17 at 15:58