QWebEngineView 调用百度地图API时报错:js: Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs. js: Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs. js: Uncaught SecurityError: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs. js: Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.
时间: 2023-12-21 07:07:21 浏览: 305
Qt5.14.0实现百度地图API的调用,使用QWebEngineView实现地图网页的显示
4星 · 用户满意度95%
这个错误提示说明在你的 QWebEngineView 中调用百度地图API时,由于你的 Cookies 和 LocalStorage 被禁用,导致无法读取和设置这些属性,从而引发了错误。解决这个问题的方法是启用 Cookies 和 LocalStorage。你可以在 QWebEngineView 中设置相应的选项来启用这些功能,如下所示:
```python
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineProfile, QWebEngineSettings
# 创建 QWebEnginePage 对象
web_page = QWebEnginePage()
# 获取 QWebEngineProfile 对象
profile = web_page.profile()
# 获取 QWebEngineSettings 对象
settings = profile.settings()
# 启用 Cookies 和 LocalStorage
settings.setAttribute(QWebEngineSettings.LocalStorageEnabled, True)
settings.setAttribute(QWebEngineSettings.CookiesEnabled, True)
```
你可以将以上代码加入到你的程序中,然后再次运行,应该就可以正常调用百度地图API了。
阅读全文