Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got "Invalid header value char" from aiohttp #49

Open
mcscope opened this issue Mar 19, 2022 · 1 comment
Open

Got "Invalid header value char" from aiohttp #49

mcscope opened this issue Mar 19, 2022 · 1 comment

Comments

@mcscope
Copy link

mcscope commented Mar 19, 2022

Hello Guy! Cool project. I am using some of your code as a reference while making my own project - something to display images from the MET on my Meural. I don't have the home assistant so I'm just robbing some of your python code to make it work.

Anyway I found an bug that I think I should tell you about, in case you hit it. I got AIOHTTP to choke on some image file and crash. This is from LocalMeural.sendPostcard
if you give it this url, aiohttp crashes
https://images.metmuseum.org/CRDImages/ep/original/DT1567.jpg

[22-03-19-0:03:51 ladyred] ~/Code/Meural > python3 main.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 898, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/usr/local/lib/python3.8/site-packages/aiohttp/streams.py", line 616, in read
    await self._waiter
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_proto.py", line 213, in data_received
    messages, upgraded, tail = self._parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message='Invalid header value char'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 21, in <module>
    asyncio.run(main())
  File "/usr/local/Cellar/python@3.8/3.8.8_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python@3.8/3.8.8_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "main.py", line 16, in main
    gal_stat = await lm.send_postcard(URL, "image/jpeg")
  File "/Users/ladyred/Code/Meural/meural/pymeural.py", line 190, in send_postcard
    response = await self.session.get(url)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 559, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 900, in start
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Invalid header value char', url=URL('https://images.metmuseum.org/CRDImages/ep/original/LC-EP_1993_132_suppl_CH-001.jpg')

So I think it is some bug with aiohttp - that it can't handle the response of the server. Maybe it is based on aiohttp version? I have a pretty recent version.

[22-03-19-0:51:07 ladyred] ~/Code/Meural > pip3 list | grep aiohttp
aiohttp             3.8.1

Anyway, you may hit it if you try this data source (the met) or that aiohttp version.

PS I rewrote it with requests library and it works fine. So it is a library issue

    response = requests.get(url)
    image = response.content
    files = {'photo': ("photo", image, content_type, "")}

PS my man, did you ever find a solution to the canvas showing the previous uploaded postcard when you hit the remote endpoint? I guess it is a meural bug but did you find any workaround?

@GuySie
Copy link
Owner

GuySie commented May 4, 2022

Hey! I did not find a solution to the previous uploaded postcard issue - mainly because, strangely enough, I have never encountered it - but @sanghviharshit has. Check out his PR for a workaround: #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants