From cbd3b71b7993f175b966a33e7440542fda61170a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 18 Mar 2018 12:12:27 +0100 Subject: [PATCH] Handle mismatches in a more pythonic way --- pyrogram/client/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 4cef260d..820c7dd1 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import base64 +import binascii import json import logging import math @@ -919,9 +920,11 @@ class Client: match = self.INVITE_LINK_RE.match(peer_id) - if match: - decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), altchars="-_") + try: + decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), "-_") return self.resolve_peer(struct.unpack(">2iq", decoded)[1]) + except (AttributeError, binascii.Error, struct.error): + pass peer_id = peer_id.lower().strip("@+")