diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -268,6 +268,11 @@ finally: self.unfakehttp() + def test_missing_local_file(self): + # see #10836 + with self.assertRaises(urllib.error.URLError): + urlopen('file://localhost/i/am/a/missing/local.file') + def test_userpass_inurl(self): self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!") try: diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1768,7 +1768,7 @@ try: stats = os.stat(localname) except OSError as e: - raise URLError(e.errno, e.strerror, e.filename) + raise URLError('local file error') size = stats.st_size modified = email.utils.formatdate(stats.st_mtime, usegmt=True) mtype = mimetypes.guess_type(url)[0]