Search code examples
pythonqtpysideghost.py

Ghost.py and proxy


Is anyone able to explain how to make Ghost.py work with a proxy? I've checked out the code but it's not there.


Solution

  • I've found it in the ghost.py file. They did a very good job in it. It's a method on line 835, as set_proxy(). It's just how to use it that I'm yet to try out:

    def set_proxy(self, type_, host='localhost', port=8888, user='',
            password=''):
        """Set up proxy for FURTHER connections.
    
        :param type_: proxy type to use: \
            none/default/socks5/https/http.
        :param host: proxy server ip or host name.
        :param port: proxy port.
        """
        _types = {
            'default': QNetworkProxy.DefaultProxy,
            'none': QNetworkProxy.NoProxy,
            'socks5': QNetworkProxy.Socks5Proxy,
            'https': QNetworkProxy.HttpProxy,
            'http': QNetworkProxy.HttpCachingProxy
        }
    
        if type_ is None:
            type_ = 'none'
        type_ = type_.lower()
        if type_ in ['none', 'default']:
            self.manager.setProxy(QNetworkProxy(_types[type_]))
            return
        elif type_ in _types:
            proxy = QNetworkProxy(_types[type_], hostName=host, port=port,
                user=user, password=password)
            self.manager.setProxy(proxy)
        else:
            raise ValueError('Unsupported proxy type:' + type_ \
            + '\nsupported types are: none/socks5/http/https/default')
    

    What I don't understand now is what "QNetworkProxy.DefaultProxy" means. It's said to be the default proxy. So, what's the default proxy?