Python Windows 身份验证用户名和密码不起作用

编程入门 行业动态 更新时间:2024-10-26 02:33:49
本文介绍了Python Windows 身份验证用户名和密码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在提示中输入数据(给出的 URL),下面的代码给了我一个错误.请帮我解决这些问题?

I am trying to enter data in prompt (URL Given), below codes is giving me an error. Please help me out with these?

from selenium import webdriver from selenium.webdrivermon.action_chains import ActionChains from selenium.webdrivermon.keys import Keys import time driver = webdriver.Firefox() url = "the-internet.herokuapp/basic_auth" driver.get(url) time.sleep(5) alert = driver.switch_to.alert alert.authenticate('admin','admin') time.sleep(4) alert.accept()

我尝试过:

ActionChains(driver).send_keys("admin").send_keys(Keys.TAB).send_keys("admin").perform()

这个也不行.

推荐答案

当您使用 Selenium 3.4.0 时,geckodriver v0.18.0、Mozilla Firefox 53.0 通过 Python 3.6.1 你可以绕过Basic Authentication 通过将 username 和 password 嵌入到 url 本身中而弹出,如下所示.

When you work with Selenium 3.4.0, geckodriver v0.18.0, Mozilla Firefox 53.0 through Python 3.6.1 you can bypass the Basic Authentication popup through embedding the username and password in the url itself as follows.

此解决方案打开 URL the-internet.herokuapp/basic_auth 并使用有效的username 和password 凭据进行身份验证.

This solution opens the URL the-internet.herokuapp/basic_auth and authenticates with a valid username and password credentials.

from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary binary = FirefoxBinary('C:\Program Files\Mozilla Firefox\firefox.exe') driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\Utility\BrowserDrivers\geckodriver.exe") driver.get("admin:admin@the-internet.herokuapp/basic_auth")

更多推荐

Python Windows 身份验证用户名和密码不起作用

本文发布于:2023-11-05 04:43:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559937.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   不起作用   用户名   密码   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!