Skip to content

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

@masterbasong

Description

@masterbasong

Hi,
I use httpx AsyncClient to send a get request ,I always get the response with null content, I change to use aiohttp ,it works ok ,get the right content.Here is my code:

EVIROMENT: python3.11.5 httpx 0.25.1

async def httpxGetUrl(url):
    async with httpx.AsyncClient() as client:
        resp = await client.get(url)
        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'))

But If I use a proxy to send the get request it will receive the right response:

async def httpxGetUrl(url):
    async with httpx.AsyncClient(
        verify=False,
        proxies=proxies,
    ) as client:
        resp = await client.get(url)
        content = await resp.aread()
        print(content)
        
        # content = resp.text
        # print(content)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions