Repository navigation
Quickstart sets r.encoding after r.text, which raises ValueError #3801
Unanswered
HighnessAtharva
asked this question in
Potential Issue
Replies: 1 comment
|
Confirmed on httpx 0.28.1. It's intentional behaviour, the quickstart just doesn't mention it. Why: the first access to >>> r = httpx.Response(200, content="héllo".encode(), headers={"content-type": "text/plain"})
>>> r.text
'héllo'
>>> r.encoding = "ISO-8859-1"
ValueError: Setting encoding after `text` has been accessed is not allowed.Workarounds, depending on what you need:
So the doc fix you propose ("set the encoding before you access |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Following the quickstart in order in one Python session, the "Text Encoding" section reads
r.textand then shows:On the current release this raises:
The setter's docstring documents that rule, but the quickstart does not, so a reader who runs the snippets in order hits it. A one-line change would fix it: "If you need to override the standard behaviour, set the encoding before you access
r.text." I can open a PR with that wording if it helps.Found by running the quickstart in a clean
python:3.11-slimcontainer with FirstRun.All reactions