aio-libs / aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
https://docs.aiohttp.org
Other
15.05k stars 2.01k forks source link

Example code uses 'content-type' when it should be 'Content-Type' #9422

Closed GM-Script-Writer-62850 closed 5 days ago

GM-Script-Writer-62850 commented 5 days ago

Describe the bug

Bug is on this line https://github.com/aio-libs/aiohttp/blob/master/README.rst?plain=1#L69

headers are case sensitive, example headers: {'Server': 'Apache/2.4.52 (Ubuntu)', 'Date': 'Sun, 06 Oct 2024 18:00:52 GMT', 'X-Frame-Options': 'DENY', 'Content-Length': '3', 'Connection': 'close', 'X-Content-Type-Options': 'nosniff', 'ETag': '"3-5ffde73223ec0"', 'Content-Type': 'text/plain', 'Accept-Ranges': 'bytes', 'Last-Modified': 'Fri, 07 Jul 2023 04:56:03 GMT'}

'Content-Type' != 'content-type' as a result a error is thrown

To Reproduce

Attempt to to run example code

Expected behavior

Example code runs without error

Logs/tracebacks

N/A

Python Version

3.12

aiohttp Version

not relevant

multidict Version

not relevant

yarl Version

not relavent

OS

Linux

Related component

Client

Additional context

No response

Code of Conduct

Dreamsorcerer commented 5 days ago

Headers are not case sensitive, headers is a CIMultiDict (where CI means case-insensitive). But, feel free to update it to the canonical form.

GM-Script-Writer-62850 commented 5 days ago

wait that works? guess it is just a downstream issue in micropython, sorry for bothering you

Dreamsorcerer commented 5 days ago

The HTTP spec says they should be considered case-insensitive, and we use CIMultiDict for that. So, yeah, should definitely work. Maybe worth playing with CIMultiDict (from multidict library) in isolation in micropython to see if there's an issue there.

GM-Script-Writer-62850 commented 5 days ago

You know looking at the correct documentation would have helped... https://github.com/micropython/micropython-lib/tree/master/python-ecosys/aiohttp

Relying on google to find what you are looking for is never a good idea now days... and what multidict would that be... guess that explains why it is case sensitive...

>>> help('modules')
__main__          asyncio/__init__  hashlib           rp2
_asyncio          asyncio/core      heapq             select
_boot             asyncio/event     io                socket
_boot_fat         asyncio/funcs     json              ssl
_onewire          asyncio/lock      lwip              struct
_rp2              asyncio/stream    machine           sys
_thread           binascii          math              time
_webrepl          bluetooth         micropython       tls
aioble/__init__   builtins          mip/__init__      uasyncio
aioble/central    cmath             neopixel          uctypes
aioble/client     collections       network           urequests
aioble/core       cryptolib         ntptime           vfs
aioble/device     deflate           onewire           webrepl
aioble/l2cap      dht               os                webrepl_setup
aioble/peripheral ds18x20           platform          websocket
aioble/security   errno             random
aioble/server     framebuf          re
array             gc                requests/__init__
Dreamsorcerer commented 5 days ago

Ah, I see. So, basically you're not using aiohttp at all. You're using some micropython library they've named aiohttp, with a partially compatible API.

GM-Script-Writer-62850 commented 5 days ago

lots of things in miropython are trimmed down due to mean ram and cpu limitations lots of things used to be named with a u at the start so micropython aiohttp would have been named uaiohttp, but they stopped using that naming system, probably cause people would just copy/paste code with no idea what they are doing and by using the same name it reduces complaints and once you have feature parody there is no reason to have a diff name and switching names between releases will break peoples code, so i guess they are just using the original name from the start, makes sense but with google begin trash in 2024... well

Dreamsorcerer commented 5 days ago

Yeah, I remember a discussion about us potentially supporting micropython ourselves, and one of the most obvious problems is that asyncio was named uasyncio, so would need a lot of if statements to work out.

I just hadn't realised that they'd started copying and shipping 3rd-party libraries as well.

GM-Script-Writer-62850 commented 5 days ago

Well in the current stable branch you can use uasyncio or asyncio and both have the same results

>>> uasyncio
<module 'uasyncio' from 'uasyncio.py'>
>>> asyncio
<module 'asyncio' from 'asyncio/__init__.py'>

i assuming uasyncio.py just imports asyncio now

Why would you need a lot of if statements, I think you could just do this

try:
 import asyncio
except:
 import uasyncio as asyncio
Dreamsorcerer commented 5 days ago

I think you could just do this

Yes, exactly, but in every module. Not needed anymore though, so maybe someone should take another look at how complex it'd be to get working directly. Given micropython have their own version now, I doubt anyone will be interested enough to try it out though.