Aug-27-2018, 11:29 AM
Hi All,
I try to make a mini web browser inside my python script
I got the below code from internet.
I modified it a little to add my proxy in it. (The proxy code was removed from the code. I use os.environ['HTTP_PROXY'] = .... )
The problem the webpage doesn't load :(
any idea how to fix that?
Here is my modified code:
I try to make a mini web browser inside my python script
I got the below code from internet.
I modified it a little to add my proxy in it. (The proxy code was removed from the code. I use os.environ['HTTP_PROXY'] = .... )
The problem the webpage doesn't load :(
any idea how to fix that?
Here is my modified code:
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtWebEngineWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.webView = QtWebEngineWidgets.QWebEngineView(self.centralwidget) self.webView.setUrl(QtCore.QUrl("http://www.google.com/")) self.webView.setObjectName("webView") self.gridLayout.addWidget(self.webView, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) from PyQt5 import QtWebEngineWidgets if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) if 'http_proxy' in os.environ: print('Proxy confgured') proxy_url = QtCore.QUrl(os.environ['http_proxy']) protocol = QtNetwork.QNetworkProxy.HttpProxy QtNetwork.QNetworkProxy.setApplicationProxy( QtNetwork.QNetworkProxy( protocol, proxy_url.host(), proxy_url.port(), proxy_url.userName(), proxy_url.password())) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())