diff -r 157da3e5b685 Lib/imghdr.py --- a/Lib/imghdr.py Mon Dec 16 14:24:50 2013 +0200 +++ b/Lib/imghdr.py Mon Dec 16 14:30:48 2013 +0200 @@ -8,7 +8,7 @@ def what(file, h=None): if h is None: - if isinstance(file, str): + if isinstance(file, (bytes, str)): f = open(file, 'rb') h = f.read(32) else: diff -r 157da3e5b685 Lib/test/test_imghdr.py --- a/Lib/test/test_imghdr.py Mon Dec 16 14:24:50 2013 +0200 +++ b/Lib/test/test_imghdr.py Mon Dec 16 14:30:48 2013 +0200 @@ -41,6 +41,12 @@ self.assertEqual(imghdr.what(TESTFN), format) + def test_bytes_path(self): + with open(TESTFN, 'wb') as stream: + stream.write(b'eggs') + self.assertIsNone(imghdr.what(TESTFN)) + self.assertIsNone(imghdr.what(TESTFN.encode())) + def test_register_test(self): def test_jumbo(h, file): if h.startswith(b'eggs'):