当用户名和密码包含特殊字符时,通过Selenium进行Python HTTP基本身份验证 [英] Python HTTP Basic Authentication through Selenium when username and password contains special characters

查看:616
本文介绍了当用户名和密码包含特殊字符时,通过Selenium进行Python HTTP基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用此构造使用默认的Selenium身份验证时,我有一个非常具体的问题username:password@siteurl.com
所以这是一个问题:如果我使用这样的密码"''asd'asd';123asd'(带有特定符号),则traceback表示URL是不正确的.但是,如果密码仅包含数字和字母,则一切正常. 以下是一个可以正常运行的代码示例,但对于我的示例,我需要用很多特定的符号填充密码,而我无权对其进行更改.

I have a very specific problem when trying to use default Selenium auth using this construction username:password@siteurl.com
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:admin@theinternet.herokuapp.com/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基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆