How to use password with special character in Basic Auth

Viewed 78

I'm using Python Telegram Bot API https://github.com/python-telegram-bot/python-telegram-bot behind the proxy. So my task is to set proxy using Basic Auth.

It works perfectly next way:

REQUEST_KWARGS = {
    "proxy_url": "https://TechLogin:Pass@word!@192.168.111.38:5050/"  # proxy example
}

updater = Updater(token=my_bot_token, request_kwargs=REQUEST_KWARGS)

But SysAdmin changed password for TechLogin and now it contains some special characters:

new_login = "-th#kr123=,1"

and requests library (or even urllib3) can't parse it:

telegram.vendor.ptb_urllib3.urllib3.exceptions.LocationParseError: Failed to parse: TechLogin:-th

Looks like it can't parse sharp symbol #

How can I escape it ?

2 Answers

You can use URL encoded values.

ex:-

# = %23

You can encode values to URL here.

"-th#kr123=,1" = "-th%23kr123%3D%2C1"



"proxy_url": "https://TechLogin:-th%23kr123%3D%2C1@192.168.111.38:5050/" 
Related