From 6bffb66b5e18fdacb1f288a72a5734a228a7dc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asiel=20D=C3=ADaz=20Ben=C3=ADtez?= Date: Sun, 8 Sep 2019 09:56:27 -0400 Subject: [PATCH] Fix mimetypes.guess_type (#471) `mimetypes.guess_type` fails if the url is something like `http://example.com/file.zip?u=10`. --- fbchat/_util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fbchat/_util.py b/fbchat/_util.py index 87dd185..aa41e0e 100644 --- a/fbchat/_util.py +++ b/fbchat/_util.py @@ -193,11 +193,12 @@ def get_files_from_urls(file_urls): r = requests.get(file_url) # We could possibly use r.headers.get('Content-Disposition'), see # https://stackoverflow.com/a/37060758 + file_name = path.basename(file_url).split("?")[0].split("#")[0] files.append( ( - path.basename(file_url).split("?")[0].split("#")[0], + file_name, r.content, - r.headers.get("Content-Type") or mimetypes.guess_type(file_url)[0], + r.headers.get("Content-Type") or mimetypes.guess_type(file_name)[0], ) ) return files