fix error if no file extension is found
This commit is contained in:
@@ -12,9 +12,12 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
import requests.exceptions as rexcepts
|
import requests.exceptions as rexcepts
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
import logging
|
||||||
from .common import BasicDownloader
|
from .common import BasicDownloader
|
||||||
from .. import config
|
from .. import config
|
||||||
|
|
||||||
|
log = logging.getLogger("http")
|
||||||
|
|
||||||
|
|
||||||
class Downloader(BasicDownloader):
|
class Downloader(BasicDownloader):
|
||||||
|
|
||||||
@@ -63,8 +66,13 @@ class Downloader(BasicDownloader):
|
|||||||
# set 'extension' keyword from Content-Type header
|
# set 'extension' keyword from Content-Type header
|
||||||
mtype = response.headers.get("Content-Type", "image/jpeg")
|
mtype = response.headers.get("Content-Type", "image/jpeg")
|
||||||
exts = mimetypes.guess_all_extensions(mtype, strict=False)
|
exts = mimetypes.guess_all_extensions(mtype, strict=False)
|
||||||
exts.sort()
|
if exts:
|
||||||
pathfmt.set_extension(exts[-1][1:])
|
exts.sort()
|
||||||
|
pathfmt.set_extension(exts[-1][1:])
|
||||||
|
else:
|
||||||
|
log.warning("No file extension found for MIME type '%s'",
|
||||||
|
mtype)
|
||||||
|
pathfmt.set_extension("txt")
|
||||||
if pathfmt.exists():
|
if pathfmt.exists():
|
||||||
self.out.skip(pathfmt.path)
|
self.out.skip(pathfmt.path)
|
||||||
response.close()
|
response.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user