pydantic / pydantic/httpx2

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

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
78
Avg merge
8h 59m
Merged PRs (30d)
24

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'))

Contributor guide

Open the contributing guide

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.

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.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.