diff --git a/scrapy/responsetypes.py b/scrapy/responsetypes.py index 147fd2628..e60ca04dd 100644 --- a/scrapy/responsetypes.py +++ b/scrapy/responsetypes.py @@ -136,7 +136,7 @@ class ResponseTypes: mimetype, encoding = self.mimetypes.guess_type(filename) if encoding: return (f"application/{encoding}".encode(),) - else: + elif mimetype: return (mimetype.encode(),) return None diff --git a/tests/test_responsetypes.py b/tests/test_responsetypes.py index 52b0e2507..2d3ae93ce 100644 --- a/tests/test_responsetypes.py +++ b/tests/test_responsetypes.py @@ -90,6 +90,7 @@ class ResponseTypesTest(unittest.TestCase): ({'filename': 'file.pdf'}, Response), ({'url': 'http://www.example.com/item/file.pdf'}, Response), ({'body': b'Some plain text data\1\2 with tabs and\n null bytes\0'}, Response), + ({'filename': '/tmp/temp^'}, TextResponse), ] for source, cls in mappings: retcls = responsetypes.from_args(**source) diff --git a/tox.ini b/tox.ini index 86e1d78f8..d31ea5517 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ deps = #mitmproxy >= 5.3.0; python_version >= '3.9' and implementation_name != 'pypy' mitmproxy >= 4.0.4; python_version >= '3.7' and python_version < '3.9' and implementation_name != 'pypy' mitmproxy >= 4.0.4, < 5; python_version >= '3.6' and python_version < '3.7' and platform_system != 'Windows' and implementation_name != 'pypy' - git+https://github.com/scrapy/xtractmime.git@binary#egg=xtractmime + git+https://github.com/scrapy/xtractmime.git@main#egg=xtractmime # Extras botocore>=1.4.87 passenv = @@ -79,6 +79,7 @@ deps = Twisted[http2]==17.9.0 w3lib==1.17.0 zope.interface==4.1.3 + git+https://github.com/scrapy/xtractmime.git@main#egg=xtractmime -rtests/requirements-py3.txt # mitmproxy 4.0.4+ requires upgrading some of the pinned dependencies