From 6e075c88fa9353400f1be34d8c2468f9ae461fc0 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 22 Apr 2020 23:08:32 +0300 Subject: [PATCH] URL-encode params in mbc auth to prevent weird errors --- maubot/cli/commands/auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/maubot/cli/commands/auth.py b/maubot/cli/commands/auth.py index 0f47c94..a3fd8b3 100644 --- a/maubot/cli/commands/auth.py +++ b/maubot/cli/commands/auth.py @@ -13,8 +13,10 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from urllib.parse import quote from urllib.request import urlopen, Request from urllib.error import HTTPError +import functools import json from colorama import Fore @@ -25,6 +27,8 @@ from ..cliq import cliq history_count: int = 10 +enc = functools.partial(quote, safe="") + @cliq.command(help="Log into a Matrix account via the Maubot server") @cliq.option("-h", "--homeserver", help="The homeserver to log into", required=True) @@ -40,7 +44,7 @@ def auth(homeserver: str, username: str, password: str, server: str, register: b if not token: return endpoint = "register" if register else "login" - req = Request(f"{server}/_matrix/maubot/v1/client/auth/{homeserver}/{endpoint}", + req = Request(f"{server}/_matrix/maubot/v1/client/auth/{enc(homeserver)}/{enc(endpoint)}", headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json",