micropython-lib/python-ecosys/aiohttp
AuroraTea 2b0d7610ce aiohttp: Fix type of header's Sec-WebSocket-Key.
The function `binascii.b2a_base64()` returns a `bytes`, but here needs a
string.  Otherwise, the value of `Sec-WebSocket-Key` in the headers will be
`b'<BASE64-ENCODED_RANDOM_VALUE>'`.

Signed-off-by: AuroraTea <1352685369@qq.com>
2024-05-24 17:26:22 +10:00
..
aiohttp aiohttp: Fix type of header's Sec-WebSocket-Key. 2024-05-24 17:26:22 +10:00
examples all: Enable ruff E401 and E402 import lints. 2024-05-17 17:06:33 +10:00
README.md aiohttp: Add new aiohttp package. 2023-12-20 16:26:04 +11:00
manifest.py aiohttp: Fix type of header's Sec-WebSocket-Key. 2024-05-24 17:26:22 +10:00

README.md

aiohttp is an HTTP client module for MicroPython asyncio module, with API mostly compatible with CPython aiohttp module.

[!NOTE] Only client is implemented.

See examples/client.py

import aiohttp
import asyncio

async def main():

    async with aiohttp.ClientSession() as session:
        async with session.get('http://micropython.org') as response:

            print("Status:", response.status)
            print("Content-Type:", response.headers['Content-Type'])

            html = await response.text()
            print("Body:", html[:15], "...")

asyncio.run(main())
$ micropython examples/client.py
Status: 200
Content-Type: text/html; charset=utf-8
Body: <!DOCTYPE html> ...