httpx use async mode make a get request,but get the null content from response

Open
#796 0 comments 0 reactions 0 assignees View on GitHub

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 @masterbasong on 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydantic/httpx2

All issues in pydantic/httpx2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.