Python Webdriver - Firefox配置文件 - 错误代码: SEC_ERROR_UNKNOWN_ISSUER

4

在整个互联网上查找了很多,但仍然无法解决在我的测试环境上运行测试脚本时出现的以下错误:

"证书不受信任,因为发行者证书未知。服务器可能没有发送适当的中间证书。可能需要导入其他根证书。"

所有软件版本如下: Firefox - 60.0.2 Python - 3.6 Selenium - 3.12.0 Gecko driver - 20.1

尝试了以下方法,但均失败: 1- 创建自定义Firefox配置文件并尝试在webdriver代码中调用

 profile = webdriver.FirefoxProfile("C:/Users/username/AppData/Roaming/Mozilla/Firefox/Profiles/p88ifbjn.Sel")
 profile.set_preference('webdriver_assume_untrusted_issuer', True)
 profile.update_preferences()
 driver = webdriver.Firefox(firefox_profile=profile)

2- 二进制代码 3 - 接受不可信代码 4 - 尝试手动接受证书

对我来说都没有用,如果有人能帮忙就告诉我,我刚开始学自动化。


提供的大多数答案都是针对Java的,需要Python的指导,请帮忙,因为我已经浪费了3天在搜索互联网上,但没有运气。 - viki
2个回答

0
这段代码对我有效:
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference("security.enterprise_roots.enabled", True)

driver = webdriver.Firefox(firefox_profile=profile)

0

我四处搜索,也找不到一个可行的答案。有趣的是,我发现通过更新一些已经讨论过的设置,它在iPython控制台中可以工作,但在终端中却不能,原因不明。所以我去比较了所有修改后的配置项在about:config中的区别。有三个首选项项目不同。在Mac OS和Ubuntu中,更新它们实际上为我带来了魔力。这里是代码。请注意,您必须通过更改默认首选项来更新它们。代码在Firefox 63.0.3中测试,使用geckodriver版本0.23.0。

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.DEFAULT_PREFERENCES['frozen']['marionette.contentListener'] = True
profile.DEFAULT_PREFERENCES['frozen']['network.stricttransportsecurity.preloadlist'] = False
profile.DEFAULT_PREFERENCES['frozen']['security.cert_pinning.enforcement_level'] = 0
profile.set_preference('webdriver_assume_untrusted_issuer', False)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", temp_folder)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                       "text/plain, image/png")
driver = webdriver.Firefox(firefox_profile=profile)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接