Skip to content

async request / socket ? #16590

Answered by Carglglz
pn2new asked this question in ESP32
Jan 15, 2025 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

I think you need to specify HTTP/1.1 version for the ClientSession e.g. get.py example returns Transfer-Encoding: chunked,

import sys

# ruff: noqa: E402
sys.path.insert(0, ".")
import aiohttp
import asyncio


URL = sys.argv.pop()

if not URL.startswith("http"):
    URL = "http://micropython.org"

print(URL)


async def fetch(client):
    async with client.get(URL) as resp:
        assert resp.status == 200
        return await resp.text()


async def main():
    async with aiohttp.ClientSession(version=aiohttp.HttpVersion11) as client:
        html = await fetch(client)
        print(html)


if __name__ == "__main__":
    asyncio.run(main())

printing headers

 $ micropython examples/get.p…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@pn2new
Comment options

@Carglglz
Comment options

Answer selected by pn2new
@pn2new
Comment options

@Carglglz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
ESP32
Labels
None yet
3 participants