Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update Lib/urllib/error.py
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
corona10 and ambv authored Dec 8, 2022
commit c3a75a14eb7ecf8832cc508b0259d0e52d54e50a
7 changes: 3 additions & 4 deletions Lib/urllib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ def __init__(self, url, code, msg, hdrs, fp):
self.hdrs = hdrs
self.fp = fp
self.filename = url
if fp is not None:
self.__super_init(fp, hdrs, url, code)
else:
self.__super_init(io.StringIO(), hdrs, url, code)
if fp is None:
fp = io.StringIO()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be BytesIO?

from urllib.request import urlopen
from urllib.error import HTTPError
try:
    urlopen('http://asadsad.sd')
except HTTPError as exception:
    content = exception.fp.read()
    print(type(content))
<class 'bytes'>

self.__super_init(fp, hdrs, url, code)

def __str__(self):
return 'HTTP Error %s: %s' % (self.code, self.msg)
Expand Down