python - 如何抑制 QWebEngineView 错误的控制台输出?

标签 python pyqt pyqt5 qwebengineview

如果我从不同工作目录中的 Python 实例创建 QWebEngineView 实例,则会收到以下错误:

[2452:9872:1108/052617.050:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[2452:9872:1108/052617.050:ERROR:cache_util.cc(135)] Unable to move cache folder C:\Users\Adam\AppData\Local\python\QtWebEngine\Default\GPUCache to C:\Users\Adam\AppData\Local\python\QtWebEngine\Default\old_GPUCache_000
[2452:9872:1108/052617.051:ERROR:disk_cache.cc(184)] Unable to create cache
[2452:9872:1108/052617.056:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import Qt
app = QtWidgets.QApplication([])
x = QtWebEngineWidgets.QWebEngineView()
x.load(QtCore.QUrl('http://example.com/'))

enter image description here

这似乎是一个已知问题,将在 QT6 中修复:https://bugreports.qt.io/browse/QTBUG-66014

但与此同时,我该如何抑制此消息?我尝试改变QtCore.qInstallMessageHandler还有x.page().javaScriptConsoleMessage = lambda self, level, msg, line, sourceID: None ,都没有影响此消息。

最佳答案

一种可能的解决方案是提高 chromium 日志的级别:

import os
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets

os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--enable-logging --log-level=3"
app = QtWidgets.QApplication([])
x = QtWebEngineWidgets.QWebEngineView()
# ...

关于python - 如何抑制 QWebEngineView 错误的控制台输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64737050/

相关文章:

python - Pandas : select row where column A does not begin with column B

python - 使用 PyQt 抓取网页图像

python - 对齐 QTableWidgetItem 会导致 item 为 None

qt - PySide如何将焦点设置到新窗口并在不存在时打开它

python - 如何将 .py 转换为 .exe(32 位)

python - 使用箭头键时根据光标位置更改 QDoubleSpinBox 中的 singleStep

python - MySQL 到云存储桶 Airflow DAG 的 UnicodeDecodeError

python - 外部 css 文件在 Flask 框架中不起作用

python - 多处理中的有序状态打印

python - PyQt - 获取所有已在 QTreeWidget 中选中的列表