AsyncClient doesn't decompress based on Content-Encoding response headers #1814
Answered
by
tomchristie
ranedk
asked this question in
Potential Issue
-
When I use Error details import httpx
import asyncio
async def run():
async with httpx.AsyncClient(headers={"accept-encoding": "gzip, deflate, br"}) as client:
response = await client.get("https://www.indeed.com/")
response_code = response.status_code
if response_code == 200:
response_text = response.content.decode("utf-8")
else:
response_text = None
return response_text, response_code Error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 4: invalid continuation byte Manual Decompress Fix import brotli # use gzip if content-encoding is gzip
import httpx
import asyncio
async def run():
async with httpx.AsyncClient(headers={"accept-encoding": "gzip, deflate, br"}) as client:
response = await client.get("https://www.indeed.com/")
response_code = response.status_code
if response_code == 200:
response_text = brotli.decompress(response.content).decode("utf-8")
else:
response_text = None
return response_text, response_code
asyncio.run(run()) Is this a bug or intended behaviour? |
Beta Was this translation helpful? Give feedback.
Answered by
tomchristie
Aug 31, 2021
Replies: 1 comment 3 replies
-
Hi - I'm not able to reproduce the behaviour you're seeing... Installation... $ pip install httpx[brotli] Usage... >>> import httpx
>>> r = httpx.get("https://www.indeed.com/")
>>> r.text
'<!DOCTYPE html>\n<html dir="ltr" lang="en">\n [...]'
>>> r.request.headers["accept-encoding"]
'gzip, deflate, br' |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tomchristie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - I'm not able to reproduce the behaviour you're seeing...
Installation...
Usage...