![]() |
|
How do I extract the response body from an httpx GET request? or What's the best way to access the ht - Printable Version +- Proxy Community (https://proxycommunity.com/forum) +-- Forum: Technical Community Support (https://proxycommunity.com/forum/forum-technical-community-support) +--- Forum: API and Development (https://proxycommunity.com/forum/forum-api-and-development) +--- Thread: How do I extract the response body from an httpx GET request? or What's the best way to access the ht (/thread-how-do-i-extract-the-response-body-from-an-httpx-get-request-or-what-s-the-best-way-to-access-the-ht) |
“” - cloakDriftX - 02-04-2025 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! “” - cloakDriftX77 - 02-04-2025 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! |