Skip to content

aiohttp is too strict when detecting charset in content_types #2197

Closed
@hynek

Description

Long story short

The presence of a ; in a content type does not mean that it contains a charset.

Expected behaviour

Only complain about charsets if there's a charset in content_type.

Actual behaviour

text/plain; version=0.0.4 will raise an ValueError: charset must not be in content_type argument.

The problem are these lines:

if content_type is not None and ";" in content_type:
raise ValueError("charset must not be in content_type "
"argument")

aiohttp just checks for a semicolon instead for the actual word charset.

Steps to reproduce

>>> from aiohttp.web import Response

>>> Response(text="hello", content_type="text/plain; version=0.0.4", charset="utf-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/hynek/.virtualenvs/prometheus_async/lib/python3.6/site-packages/aiohttp/web_response.py", line 451, in __init__
    raise ValueError("charset must not be in content_type "
ValueError: charset must not be in content_type argument
charset must not be in content_type argument

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions