harshil21 · GitHub

Deletes the Bot._validate_token step since bot tokens could change in the future. Now whenever an InvalidToken exception is raised, the token is printed along with it so the user can see where they went wrong.


Original proposal:

Improves PTB's verification of bot tokens and also adds a better error message along the way. Suppose your bot token is 123456:AAF5_-y.ert. So the error message now shows:

E telegram.error.InvalidToken: Illegal character found in bot token:
E 123456:AAF5_-y.ert
E               ^

We could also add another check where we assert that the no. of chars after : is 34 or 35. I say 34 since in https://core.telegram.org/bots/#creating-a-new-bot it's 34, but I have only seen it be 35 though. I didn't add this since it might be too strict and could have false positives in the future?

Checklist for PRs

  • Added .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s

Read the original on github.com ↗