skip to Main Content

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@[email protected]: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


  1. 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%[email protected]:5050/" 
    
    Login or Signup to reply.
  2. You must use URL-encoding, as shown in this post:

    Escaping username characters in basic auth URLs

    This way the # in the password becomes %23

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search