twirpy
twirpy copied to clipboard
Missing Content-Type returns "got non-twirp exception while processing request"
If Content-Type is missing from the request, Twirpy returns a 500 response code instead of gracefully handling the error.
Make any request without a Content-Type. This error will be raised.
Error: got non-twirp exception while processing request
Trace:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/twirp/asgi.py", line 62, in __call__
encoder, decoder = self._get_encoder_decoder(endpoint, headers)
File "/usr/local/lib/python3.10/site-packages/twirp/base.py", line 104, in _get_encoder_decoder
message="unexpected Content-Type: " + ctype
TypeError: can only concatenate str (not "NoneType") to str
See the code below. ctype = headers.get('content-type', None) sets ctype to None then attempts to concatenate the None type to a string in message="unexpected Content-Type: " + ctype while building the BadRoute error.
https://github.com/verloop/twirpy/blob/69400300476dc3a7a0d29ab52fb63ae216eee350/twirp/base.py#L93-L106