2

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 ?

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102

2 Answers2

0

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/" 
Miyuru
  • 53
  • 2
  • 7
  • 1
    Hi, thank you for response! Can you show the whole example please? Because just changing # to %23 doesn't work: `Tunnel connection failed: 407 authenticationrequired`. This means, urllib3 accept `%23` as 3 different symbols and says that password is incorrect – Mikhail_Sam Jul 19 '22 at 09:52
  • nope still doesn't work. I tried this solution also tried to set env var in the same way - always `407 authenticationrequired` :( – Mikhail_Sam Jul 19 '22 at 10:10
  • Also tried it using `curl` - curl can handle # (successfully connected!) but can't handle using URL-encoding... – Mikhail_Sam Jul 19 '22 at 10:14
0

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

Dyn4sty
  • 166
  • 4
  • Hi, thank you for response! Can you show the whole example please? I get `Tunnel connection failed: 407 authenticationrequired.` Looks like urllib3 accepts %23 as 3 different symbols and says that password is incorrect – Mikhail_Sam Jul 19 '22 at 09:58