httpx use async mode make a get request,but get the null content from response
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- python
- Domain
- networking
Research direction
Start by reproducing the reported AsyncClient request in httpxGetUrl against the stated local URL, then compare its status, headers, and content with the aiohttpGetUrl version. Read the AsyncClient response-reading behavior around aread() and resp.text; done means identifying a reproducible cause for the empty content and documenting or testing the resulting behavior.
Written by the indexing model from the issue text.
Description
Originally opened by
@masterbasongon 2023-11-22 16:57:11 in encode/httpx
Hi,
I use httpx AsyncClient to send a get request ,but always get the resonse content null, I change to use aiohttp ,it works ok ,get the right content.Here is my code:
async def httpxGetUrl(url):
async with httpx.AsyncClient() as client:
headers = {
'Connection':'close'
}
resp = await client.get(url,headers=headers)
client
content = await resp.aread()
print(content)
# content = resp.text
# print(content)
async def aiohttpGetUrl(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
token = await resp.text()
print(token.encode('utf-8').decode('unicode_escape'))
return token
if __name__ == '__main__':
import asyncio
asyncio.run(httpxGetUrl('http://127.0.0.1:5000/Pay?Id=655cede5-5a3b-401d-00cf-9753508162e4'))
# asyncio.run(aiohttpGetUrl('http://127.0.0.1:5000/Pay?Id=655cede5-5a3b-401d-00cf-9753508162e4'))
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 103
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pydantic/httpx2
-
Please revert aiter_bytes signature to AsyncIteratorMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#1158 · 2 comments ·
Maintainers usually reply within 1 day
-
Export AutoBackendMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
pydantic/httpx2#1131 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Mention header name error message for invalid header encodingsMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#864 · 3 comments ·
Maintainers usually reply within 1 day
-
Support DigestAuth with "x-www-authenticate" in first response headerPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug frontend
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vendrabuck/HERD#1419 ·
Maintainers usually reply within 1 day