'I get "Release of profile requested but WebEnginePage still not deleted. Expect troubles !" even after calling app.exec()
I have a python code like below
import sys
from PyQt5 import QtWidgets, QtWebEngineWidgets
from PyQt5.QtNetwork import QNetworkCookie
from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtGui import QPageLayout, QPageSize
from PyQt5.QtWidgets import QApplication
import argparse
def main(app):
url = ''
parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--url", help="Type url")
args = parser.parse_args()
config = vars(args)
url = config['url']
loader = QtWebEngineWidgets.QWebEngineView()
profile = QtWebEngineWidgets.QWebEngineProfile("storage", loader)
cookie_store = profile.cookieStore()
with open('cookie.txt', 'rb') as f:
contents = f.read()
cookie_store.setCookie(QNetworkCookie(contents))
webpage = QtWebEngineWidgets.QWebEnginePage(profile, loader)
COOKIPATH = "./Cache" + str(1)
# web_profile.setCachePath(COOKIPATH)
profile.setPersistentStoragePath(COOKIPATH)
profile.setPersistentCookiesPolicy(2)
loader.setPage(webpage)
loader.setZoomFactor(1)
layout = QPageLayout()
layout.setPageSize(QPageSize(QPageSize.A4Extra))
layout.setOrientation(QPageLayout.Portrait)
loader.load(QUrl(url))
loader.page().pdfPrintingFinished.connect(lambda *args: QApplication.exit())
def emit_pdf(finished):
QTimer.singleShot(2000, lambda: loader.page().printToPdf("test.pdf", pageLayout=layout))
loader.loadFinished.connect(emit_pdf)
app.exec()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
main(app)
I run above code like this python3 htmlToPdfnew.py --url http://example.com
but when I run the code I get a warning like below
Release of profile requested but WebEnginePage still not deleted. Expect troubles !
based on suggestions I got from internet calling app.exec()
but still get that error
how to resolve that error ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|