How do I extract the response body from an httpx GET request? or What's the best way to access the ht

22 Replies, 1928 Views

Oh man, I feel you. The httpx get response body tripped me up too. Here’s the scoop:
- `.text`: String version of the body.
- `.content`: Bytes (good for non-text stuff).
- `.json()`: If it’s JSON, this’ll parse it.

Try:
```python
response = httpx.get("https://example.com")
print(response.text)
```
And hey, no dumb questions—we’ve all been there!
Wow, thanks everyone! Didn’t realize `.body` wasn’t a thing in httpx. Tried `response.text` and it worked perfectly.

Follow-up: What if the encoding’s weird? Some characters look broken. Should I mess with `response.encoding` or just stick with `.content` and decode manually?

Also, big thanks for the `.json()` tip—saved me a bunch of time!



Users browsing this thread: 1 Guest(s)