Python PyQT5 WebEngine Segmentation fault 错误
Python PyQT5 WebEngine Segmentation fault Error
我想创建一个应用程序来下载 ms store 应用程序,它 运行 很好,直到今天我尝试打开该网站 (https://apps.microsoft.com/) pyqt5 window 崩溃并且它显示 'Segmentation fault',当我尝试加载像 microsoft.com 或 google.com 这样的页面时它工作正常当我在 microsoft.com 和页面 returns 中搜索应用程序时崩溃以 'https://apps.microsoft.com/...' 开头的 url 它因 'Segmentation fault' 错误
而崩溃
# importing required libraries
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
import os
import sys
# creating main window class
class MainWindow(QMainWindow):
# constructor
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
# creating a QWebEngineView
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("https://apps.microsoft.com/")) #if you change this to something like google.com or microsoft.com it works fine but when you try to access a site that starts with something like this you get error
# adding action when url get changed
self.browser.urlChanged.connect(self.update_urlbar)
# adding action when loading is finished
self.browser.loadFinished.connect(self.update_title)
# set this browser as central widget or main window
self.setCentralWidget(self.browser)
# creating a status bar object
self.status = QStatusBar()
# adding status bar to the main window
self.setStatusBar(self.status)
# creating QToolBar for navigation
navtb = QToolBar("Navigation")
# adding this tool bar tot he main window
self.addToolBar(navtb)
# adding actions to the tool bar
# creating a action for back
back_btn = QAction("Back", self)
# setting status tip
back_btn.setStatusTip("Back to previous page")
# adding action to the back button
# making browser go back
back_btn.triggered.connect(self.browser.back)
# adding this action to tool bar
navtb.addAction(back_btn)
# similarly for forward action
next_btn = QAction("Forward", self)
next_btn.setStatusTip("Forward to next page")
# adding action to the next button
# making browser go forward
next_btn.triggered.connect(self.browser.forward)
navtb.addAction(next_btn)
# similarly for reload action
reload_btn = QAction("Reload", self)
reload_btn.setStatusTip("Reload page")
# adding action to the reload button
# making browser to reload
reload_btn.triggered.connect(self.browser.reload)
navtb.addAction(reload_btn)
# similarly for home action
home_btn = QAction("Home", self)
home_btn.setStatusTip("Go home")
home_btn.triggered.connect(self.navigate_home)
navtb.addAction(home_btn)
# adding a separator in the tool bar
navtb.addSeparator()
# creating a line edit for the url
self.urlbar = QLineEdit()
# adding action when return key is pressed
self.urlbar.returnPressed.connect(self.navigate_to_url)
# adding this to the tool bar
navtb.addWidget(self.urlbar)
# adding stop action to the tool bar
stop_btn = QAction("Stop", self)
stop_btn.setStatusTip("Stop loading current page")
# adding action to the stop button
# making browser to stop
stop_btn.triggered.connect(self.browser.stop)
navtb.addAction(stop_btn)
# showing all the components
self.show()
# method for updating the title of the window
def update_title(self):
title = self.browser.page().title()
self.setWindowTitle("% s - Geek Browser" % title)
# method called by the home action
def navigate_home(self):
# open the google
self.browser.setUrl(QUrl("http://www.google.com"))
# method called by the line edit when return key is pressed
def navigate_to_url(self):
# getting url and converting it to QUrl object
q = QUrl(self.urlbar.text())
# if url is scheme is blank
if q.scheme() == "":
# set url scheme to html
q.setScheme("http")
# set the url to the browser
self.browser.setUrl(q)
# method for updating url
# this method is called by the QWebEngineView object
def update_urlbar(self, q):
# setting text to the url bar
self.urlbar.setText(q.toString())
# setting cursor position of the url bar
self.urlbar.setCursorPosition(0)
# creating a pyQt5 application
app = QApplication(sys.argv)
# setting name to the application
app.setApplicationName("Geek Browser")
# creating a main window object
window = MainWindow()
# loop
app.exec_()
我基本上克隆了 geeksforgeeks 简单浏览器 (https://www.geeksforgeeks.org/creating-a-simple-browser-using-pyqt5/) 并对其进行了更改,因此它的行为也相同我认为微软对站点进行了一些更改,因为它昨天运行良好。
谁能帮我解决这个问题,我想从网站上获取 url 的应用程序。
好吧,我找到了问题的答案,答案只是升级到最新的 pyqt6(https://pypi.org/project/PyQt6/) and use pyqt6-webengine(https://pypi.org/project/PyQt6-WebEngine/), the pyqt5-webengine was implemented using chroimium 87 and the pyqt6-webengine was implemented using chromium 90 (https://wiki.qt.io/QtWebEngine/ChromiumVersions),它会自动将 http 请求升级到 https。
在 pyqt5 中我得到了这个错误
js: Mixed Content: The page at 'https://www.microsoft.com/en-in' was loaded over HTTPS, but requested an insecure image 'http://arc.msn.com/v3/Delivery/Events/Impression?PID=425107905&TID=700346678&CID=128000000003037669&BID=1794732536&PG=PC000P0FR5.0000000IQX&TPID=425107905&ASID=001880bd94094f85a068a36faf64dcc8&BCNT=1&PG=PC000P0FR5.0000000IQX&UNID=318922&MAP_TID=14964BA1-C3BA-47F4-9E0C-84F0E8F87A52&ASID=FD46F1A327D7474EBFE5E7A37D3D2ABC&REQASID=FD46F1A327D7474EBFE5E7A37D3D2ABC&ARC=1&EMS=1&LOCALE=EN-IN&COUNTRY=IN&HTD=-1&LANG=16393&DEVLANG=EN&CIP=52.230.41.54&ID=3E20CD16E70260B91F34DC64E6B06116&OPTOUTSTATE=0&MARKETBASEDCOUNTRY=IN&CFMT=&SFT=GIF%2CAGIF%2CJPEG%2CJPG%2CBMP%2CPNG&H=320&W=240&FESVER=1.3&DEVFAM=WINDOWS.DESKTOP&ARCH=X86&APIVER=7000&AS=T&AS1=T&AS2=T&CHNL=CFD&UIT=G'. This content should also be served over HTTPS.
process is terminated with return code 3221225477.
我在胡说这意味着它无法处理请求,因为它是作为 http 请求和站点 运行 https 发出的,因此应用程序自 pyqt5-webengine(旧版本的铬)以来崩溃了没有自动将 http 请求升级为 https。
升级到pyqt6后
js: Mixed Content: The page at 'https://www.microsoft.com/en-in/' was loaded over HTTPS, but requested an insecure element 'http://arc.msn.com/v3/Delivery/Events/Impression?PID=425107905&TID=700346678&CID=128000000003037669&BID=1368990958&PG=PC000P0FR5.0000000IQX&TPID=425107905&ASID=595dbd04fa15459fa34c9c2e09767c7f&BCNT=1&PG=PC000P0FR5.0000000IQX&UNID=318922&MAP_TID=5E7FABA2-C730-4EE2-8234-FF66A1A9BB9D&ASID=30465AA3C164432A80ECBC230628569F&REQASID=30465AA3C164432A80ECBC230628569F&ARC=1&EMS=1&LOCALE=EN-IN&COUNTRY=IN&HTD=-1&LANG=16393&DEVLANG=EN&CIP=52.230.41.54&ID=064BAED440726CB73AFABF7541856DF7&OPTOUTSTATE=0&MARKETBASEDCOUNTRY=IN&CFMT=&SFT=GIF%2CAGIF%2CJPEG%2CJPG%2CBMP%2CPNG&H=320&W=240&FESVER=1.3&DEVFAM=WINDOWS.DESKTOP&ARCH=X86&APIVER=7000&AS=T&AS1=T&AS2=T&CHNL=CFD&UIT=G'. This request was automatically upgraded to HTTPS, For more information see https://blog.chromium.org/2019/10/no-more-mixed-messages-about-https.html
所以在我更改为 pyqt6 之后出现了同样的错误,但它没有崩溃并给我错误代码,而是自动将请求升级到 https(因为它使用了更新版本的铬)。我想如果你能以某种方式让 pyqt5 使用最新版本的铬,它应该可以工作,但我不知道它是否可能或如何做。
如果我错了,请随时纠正我。我不是 python 或 pyqt 方面的专家,但是升级到 pyqt6 的这个解决方案对我有用并解决了我的问题。
我想创建一个应用程序来下载 ms store 应用程序,它 运行 很好,直到今天我尝试打开该网站 (https://apps.microsoft.com/) pyqt5 window 崩溃并且它显示 'Segmentation fault',当我尝试加载像 microsoft.com 或 google.com 这样的页面时它工作正常当我在 microsoft.com 和页面 returns 中搜索应用程序时崩溃以 'https://apps.microsoft.com/...' 开头的 url 它因 'Segmentation fault' 错误
而崩溃# importing required libraries
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
import os
import sys
# creating main window class
class MainWindow(QMainWindow):
# constructor
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
# creating a QWebEngineView
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("https://apps.microsoft.com/")) #if you change this to something like google.com or microsoft.com it works fine but when you try to access a site that starts with something like this you get error
# adding action when url get changed
self.browser.urlChanged.connect(self.update_urlbar)
# adding action when loading is finished
self.browser.loadFinished.connect(self.update_title)
# set this browser as central widget or main window
self.setCentralWidget(self.browser)
# creating a status bar object
self.status = QStatusBar()
# adding status bar to the main window
self.setStatusBar(self.status)
# creating QToolBar for navigation
navtb = QToolBar("Navigation")
# adding this tool bar tot he main window
self.addToolBar(navtb)
# adding actions to the tool bar
# creating a action for back
back_btn = QAction("Back", self)
# setting status tip
back_btn.setStatusTip("Back to previous page")
# adding action to the back button
# making browser go back
back_btn.triggered.connect(self.browser.back)
# adding this action to tool bar
navtb.addAction(back_btn)
# similarly for forward action
next_btn = QAction("Forward", self)
next_btn.setStatusTip("Forward to next page")
# adding action to the next button
# making browser go forward
next_btn.triggered.connect(self.browser.forward)
navtb.addAction(next_btn)
# similarly for reload action
reload_btn = QAction("Reload", self)
reload_btn.setStatusTip("Reload page")
# adding action to the reload button
# making browser to reload
reload_btn.triggered.connect(self.browser.reload)
navtb.addAction(reload_btn)
# similarly for home action
home_btn = QAction("Home", self)
home_btn.setStatusTip("Go home")
home_btn.triggered.connect(self.navigate_home)
navtb.addAction(home_btn)
# adding a separator in the tool bar
navtb.addSeparator()
# creating a line edit for the url
self.urlbar = QLineEdit()
# adding action when return key is pressed
self.urlbar.returnPressed.connect(self.navigate_to_url)
# adding this to the tool bar
navtb.addWidget(self.urlbar)
# adding stop action to the tool bar
stop_btn = QAction("Stop", self)
stop_btn.setStatusTip("Stop loading current page")
# adding action to the stop button
# making browser to stop
stop_btn.triggered.connect(self.browser.stop)
navtb.addAction(stop_btn)
# showing all the components
self.show()
# method for updating the title of the window
def update_title(self):
title = self.browser.page().title()
self.setWindowTitle("% s - Geek Browser" % title)
# method called by the home action
def navigate_home(self):
# open the google
self.browser.setUrl(QUrl("http://www.google.com"))
# method called by the line edit when return key is pressed
def navigate_to_url(self):
# getting url and converting it to QUrl object
q = QUrl(self.urlbar.text())
# if url is scheme is blank
if q.scheme() == "":
# set url scheme to html
q.setScheme("http")
# set the url to the browser
self.browser.setUrl(q)
# method for updating url
# this method is called by the QWebEngineView object
def update_urlbar(self, q):
# setting text to the url bar
self.urlbar.setText(q.toString())
# setting cursor position of the url bar
self.urlbar.setCursorPosition(0)
# creating a pyQt5 application
app = QApplication(sys.argv)
# setting name to the application
app.setApplicationName("Geek Browser")
# creating a main window object
window = MainWindow()
# loop
app.exec_()
我基本上克隆了 geeksforgeeks 简单浏览器 (https://www.geeksforgeeks.org/creating-a-simple-browser-using-pyqt5/) 并对其进行了更改,因此它的行为也相同我认为微软对站点进行了一些更改,因为它昨天运行良好。
谁能帮我解决这个问题,我想从网站上获取 url 的应用程序。
好吧,我找到了问题的答案,答案只是升级到最新的 pyqt6(https://pypi.org/project/PyQt6/) and use pyqt6-webengine(https://pypi.org/project/PyQt6-WebEngine/), the pyqt5-webengine was implemented using chroimium 87 and the pyqt6-webengine was implemented using chromium 90 (https://wiki.qt.io/QtWebEngine/ChromiumVersions),它会自动将 http 请求升级到 https。
在 pyqt5 中我得到了这个错误
js: Mixed Content: The page at 'https://www.microsoft.com/en-in' was loaded over HTTPS, but requested an insecure image 'http://arc.msn.com/v3/Delivery/Events/Impression?PID=425107905&TID=700346678&CID=128000000003037669&BID=1794732536&PG=PC000P0FR5.0000000IQX&TPID=425107905&ASID=001880bd94094f85a068a36faf64dcc8&BCNT=1&PG=PC000P0FR5.0000000IQX&UNID=318922&MAP_TID=14964BA1-C3BA-47F4-9E0C-84F0E8F87A52&ASID=FD46F1A327D7474EBFE5E7A37D3D2ABC&REQASID=FD46F1A327D7474EBFE5E7A37D3D2ABC&ARC=1&EMS=1&LOCALE=EN-IN&COUNTRY=IN&HTD=-1&LANG=16393&DEVLANG=EN&CIP=52.230.41.54&ID=3E20CD16E70260B91F34DC64E6B06116&OPTOUTSTATE=0&MARKETBASEDCOUNTRY=IN&CFMT=&SFT=GIF%2CAGIF%2CJPEG%2CJPG%2CBMP%2CPNG&H=320&W=240&FESVER=1.3&DEVFAM=WINDOWS.DESKTOP&ARCH=X86&APIVER=7000&AS=T&AS1=T&AS2=T&CHNL=CFD&UIT=G'. This content should also be served over HTTPS.
process is terminated with return code 3221225477.
我在胡说这意味着它无法处理请求,因为它是作为 http 请求和站点 运行 https 发出的,因此应用程序自 pyqt5-webengine(旧版本的铬)以来崩溃了没有自动将 http 请求升级为 https。
升级到pyqt6后
js: Mixed Content: The page at 'https://www.microsoft.com/en-in/' was loaded over HTTPS, but requested an insecure element 'http://arc.msn.com/v3/Delivery/Events/Impression?PID=425107905&TID=700346678&CID=128000000003037669&BID=1368990958&PG=PC000P0FR5.0000000IQX&TPID=425107905&ASID=595dbd04fa15459fa34c9c2e09767c7f&BCNT=1&PG=PC000P0FR5.0000000IQX&UNID=318922&MAP_TID=5E7FABA2-C730-4EE2-8234-FF66A1A9BB9D&ASID=30465AA3C164432A80ECBC230628569F&REQASID=30465AA3C164432A80ECBC230628569F&ARC=1&EMS=1&LOCALE=EN-IN&COUNTRY=IN&HTD=-1&LANG=16393&DEVLANG=EN&CIP=52.230.41.54&ID=064BAED440726CB73AFABF7541856DF7&OPTOUTSTATE=0&MARKETBASEDCOUNTRY=IN&CFMT=&SFT=GIF%2CAGIF%2CJPEG%2CJPG%2CBMP%2CPNG&H=320&W=240&FESVER=1.3&DEVFAM=WINDOWS.DESKTOP&ARCH=X86&APIVER=7000&AS=T&AS1=T&AS2=T&CHNL=CFD&UIT=G'. This request was automatically upgraded to HTTPS, For more information see https://blog.chromium.org/2019/10/no-more-mixed-messages-about-https.html
所以在我更改为 pyqt6 之后出现了同样的错误,但它没有崩溃并给我错误代码,而是自动将请求升级到 https(因为它使用了更新版本的铬)。我想如果你能以某种方式让 pyqt5 使用最新版本的铬,它应该可以工作,但我不知道它是否可能或如何做。
如果我错了,请随时纠正我。我不是 python 或 pyqt 方面的专家,但是升级到 pyqt6 的这个解决方案对我有用并解决了我的问题。