问题描述
当尝试使用此构造使用默认的Selenium身份验证时,我有一个非常具体的问题username:[email protected]
所以这是一个问题:如果我使用这样的密码"''asd'asd';123asd'
(带有特定符号),则traceback
表示URL
是不正确的.但是,如果密码仅包含数字和字母,则一切正常.以下是一个可以正常运行的代码示例,但对于我的示例,我需要用很多特定的符号填充密码,而我无权对其进行更改.
I have a very specific problem when trying to use default Selenium auth using this construction username:[email protected]
So here is an issue: if I use a password like this "''asd'asd';123asd'
(with specific symbols) traceback
will say that URL
is incorrect. But if the password is just with numbers and letters -- everything is OK.Below is an example of a code that works correctly but for my example, I need to fill password with a lot of specific symbols and I don't have permission to change it.
import unittest
from selenium import webdriver
class LoggedTest(unittest.TestCase):
@classmethod
def setUp(inst):
# create a new Chrome session """
inst.driver = webdriver.Chrome()
inst.driver.implicitly_wait(30)
inst.driver.maximize_window()
# navigate to the application home page """
inst.driver.get("http://admin:[email protected]/basic_auth")
推荐答案
如果密码包含符号,例如基本身份验证. "''asd'asd';123asd'
,您需要> 翻译 字符串放入 UTF .例如:
For Basic Authentication if the Password contains symbols e.g. "''asd'asd';123asd'
you need to translate the string into UTF. As an example:
username = "%21%40user" #stands for !@user
password = "%0D%0Apass" #stands for ^&pass
webpage = "something.url.com"
现在您可以使用:
url = 'http://{}:{}@{}'.format(username, password, webpage)
driver.get(url)
这篇关于当用户名和密码包含特殊字符时,通过Selenium进行Python HTTP基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!