Skip to content

HTTPError fp.read returns string instead of bytes  #101936

Closed
@gaborbernat

Description

@gaborbernat

Due to https://github.com/python/cpython/pull/99966/files

However, this returns a bytes stream on the live run:

from http import HTTPStatus
from mailbox import Message
from urllib.error import HTTPError
from urllib.request import urlopen

try:
    urlopen("http://asadsad.sd")
except HTTPError as exception:
    content = exception.fp.read()
    print(type(content))

error = HTTPError(url="url", code=HTTPStatus.IM_A_TEAPOT, msg="msg", hdrs=Message(), fp=None)
print(type(error.fp.read()))
<class 'bytes'>
<class 'str'>

Linked PRs

Metadata

Metadata

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions