Fix mimetypes.guess_type (#471)

`mimetypes.guess_type` fails if the url is something like `http://example.com/file.zip?u=10`.

Backported from 6bffb66
This commit is contained in:
Asiel Díaz Benítez
2019-09-08 09:56:27 -04:00
committed by Mads Marquart
parent 3d28c958d3
commit bb1f7d9294

View File

@@ -219,11 +219,12 @@ def get_files_from_urls(file_urls):
r = requests.get(file_url) r = requests.get(file_url)
# We could possibly use r.headers.get('Content-Disposition'), see # We could possibly use r.headers.get('Content-Disposition'), see
# https://stackoverflow.com/a/37060758 # https://stackoverflow.com/a/37060758
file_name = basename(file_url).split("?")[0].split("#")[0]
files.append( files.append(
( (
basename(file_url).split("?")[0].split("#")[0], file_name,
r.content, r.content,
r.headers.get("Content-Type") or guess_type(file_url)[0], r.headers.get("Content-Type") or guess_type(file_name)[0],
) )
) )
return files return files