def handle_error(self, socket_error):
        """Some error happened while connecting."""
        error_description = "%s (%d)" % (self.errorString(), socket_error)
        logger.error("connection error: %s", error_description)
        if self.connected_d.called:
            return

        if socket_error == self.ProxyAuthenticationRequiredError:
            error = ProxyAuthenticationError(407, error_description)
        else:
            error = ConnectionError(500, error_description)

        self.connected_d.errback(error)
Ejemplo n.º 2
0
def build_proxy(settings_groups):
    """Create a QNetworkProxy from these settings."""
    proxy_groups = [
        ("socks", QNetworkProxy.Socks5Proxy),
        ("https", QNetworkProxy.HttpProxy),
        ("http", QNetworkProxy.HttpProxy),
    ]
    for group, proxy_type in proxy_groups:
        if group not in settings_groups:
            continue
        settings = settings_groups[group]
        if "host" in settings and "port" in settings:
            return QNetworkProxy(proxy_type,
                                 hostName=settings.get("host", ""),
                                 port=settings.get("port", 0),
                                 user=settings.get("username", ""),
                                 password=settings.get("password", ""))
    logger.error("No proxy correctly configured.")
    return QNetworkProxy(QNetworkProxy.DefaultProxy)