def modifyProxy(self, text): # After setting the proxy it could be necessary to update active connection. See QGSAuthMethod / QgsAuthManager self.proxy = self.getProxy(self.config[text]) QNetworkProxy.setApplicationProxy(self.proxy) # excludes=self.config[text]['noProxy'], noProxyURLs=self.config[text]['noProxy'] self.networkManager.setFallbackProxyAndExcludes( self.proxy, [], self.config[text]['noProxy']) # self.networkManager.setProxy(self.proxy) '''
def setProxy(self): try: val = self.paramCfg('Proxy', 'False') if self.intranet and val == 'True': proxy = QNetworkProxy() proxy.setType(QNetworkProxy.DefaultProxy) proxy.setHostName = _PROXY['HostName'] proxy.setPort = _PROXY['Port'] proxy.setApplicationProxy(proxy) return proxy else: return None except Exception as err: self.bugException(err) return None
def __init__(self, parentInstance): super(mapillaryViewer, self).__init__() self.parentInstance = parentInstance self.viewport = parentInstance.dlg.webView #self.viewport.statusBarMessage.connect(self.getJSONmessage) self.viewport.page().mainFrame().javaScriptWindowObjectCleared.connect( self.registerJS) self.locationKey = None WS = self.viewport.settings() WS.setAttribute(QWebSettings.JavascriptEnabled, True) WS.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) WS.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True) WS.setAttribute(QWebSettings.PrintElementBackgrounds, True) WS.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True) WS.setAttribute(QWebSettings.LocalStorageEnabled, True) WS.setAttribute(QWebSettings.PluginsEnabled, True) WS.setAttribute(QWebSettings.WebGLEnabled, True) self.viewport.page().setNetworkAccessManager( QgsNetworkAccessManager.instance()) self.mly_api = mapillaryApi() self.page = 'https://enricofer.github.io/go2mapillary/res/browser.html' self.openLocation('') self.enabled = True proxy_conf = getProxySettings() if proxy_conf: proxy = QNetworkProxy() if proxy_conf['type'] == "DefaultProxy": proxy.setType(QNetworkProxy.DefaultProxy) elif proxy_conf['type'] == "Socks5Proxy": proxy.setType(QNetworkProxy.Socks5Proxy) elif proxy_conf['type'] == "HttpProxy": proxy.setType(QNetworkProxy.HttpProxy) elif proxy_conf['type'] == "HttpCachingProxy": proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxy_conf['type'] == "FtpCachingProxy": proxy.setType(QNetworkProxy.FtpCachingProxy) proxy.setHostName(proxy_conf['host']) proxy.setPort(int(proxy_conf['port'])) proxy.setUser(proxy_conf['user']) proxy.setPassword(proxy_conf['password']) QNetworkProxy.setApplicationProxy(proxy)
def __init__(self, viewport): super(mapillaryViewer, self).__init__() self.viewport = viewport self.viewport.statusBarMessage.connect(self.getJSONmessage) WS = self.viewport.settings() WS.setAttribute(QWebSettings.JavascriptEnabled,True) WS.setAttribute(QWebSettings.DeveloperExtrasEnabled,True) WS.setAttribute(QWebSettings.JavascriptCanAccessClipboard,True) WS.setAttribute(QWebSettings.PrintElementBackgrounds,True) WS.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled,True) WS.setAttribute(QWebSettings.LocalStorageEnabled,True) WS.setAttribute(QWebSettings.PluginsEnabled,True) WS.setAttribute(QWebSettings.WebGLEnabled,True) self.viewport.page().setNetworkAccessManager(QgsNetworkAccessManager.instance()) s = QSettings() #getting proxy from qgis options settings proxyEnabled = s.value("proxy/proxyEnabled", "") proxyType = s.value("proxy/proxyType", "" ) proxyHost = s.value("proxy/proxyHost", "" ) proxyPort = s.value("proxy/proxyPort", "" ) proxyUser = s.value("proxy/proxyUser", "" ) proxyPassword = s.value("proxy/proxyPassword", "" ) print (proxyEnabled+"; "+proxyType+"; "+proxyHost+"; " + proxyPort+"; " + proxyUser+"; " +proxyPassword) if proxyEnabled == "true": # test if there are proxy settings proxy = QNetworkProxy() if proxyType == "DefaultProxy": proxy.setType(QNetworkProxy.DefaultProxy) elif proxyType == "Socks5Proxy": proxy.setType(QNetworkProxy.Socks5Proxy) elif proxyType == "HttpProxy": proxy.setType(QNetworkProxy.HttpProxy) elif proxyType == "HttpCachingProxy": proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxyType == "FtpCachingProxy": proxy.setType(QNetworkProxy.FtpCachingProxy) proxy.setHostName(proxyHost) proxy.setPort(int(proxyPort)) proxy.setUser(proxyUser) proxy.setPassword(proxyPassword) #QNetworkProxy.setApplicationProxy(proxy) #self.page = os.path.join(os.path.dirname(__file__),'res','browser.html') self.page = os.path.join('https://enricofer.github.io/go2mapillary/res/browser.html') self.openLocation('') self.enabled = True print (self.page)
def getProxy(self, option): return QNetworkProxy(QNetworkProxy.HttpProxy, hostName=option['host'], port=option['port'], user=option['user'], password=self.getPasswordB64(option))