Open ghost opened 2 years ago
Even more baffling is, that when I sent the dysfunctional Android request manually using CURL, the server responds just fine to it with 200.
$ curl -X 'GET' '<ip:port>/places/18526165' -H 'Accept-Encoding: gzip' -H 'Connection: Keep-Alive' -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; SM-J330F Build/PPR1.180610.011'
Resulting dump:
Host: <ip:port>
Accept: */*
Accept-Encoding: gzip
Connection: Keep-Alive
User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; SM-J330F Build/PPR1.180610.011
It looks like the android request is maybe setting an accept
header that the flask-restx app doesn't support.
The bit of code in question in api.py
is:
mediatype = request.accept_mimetypes.best_match(
self.representations, default=default_mediatype,
)
Can you manually set the accept:
http header in your android request to application/json
?
Hello Peter, thanks for the answer. I first thought that I created the very same GET-request using curl, but now I tcpdumped it and saw thaw that curl sends default headers I was not aware of.
Indead, you found the problem, I can reproduce it using curl now:
$ curl -X 'GET' '<url>' -H 'Accept-Encoding: gzip' -H 'Connection: Keep-Alive' -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; SM-J330F Build/PPR1.180610.011' -H 'Accept:'
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
Thanks, so all I got to do is add an Accept
header. :) You just saved my day.
I would recommend adjusting flask_restx
to either throwing a more explicit error message or allowing to remove the header when sending a request as this is no behavior someone with rudimentary understanding of HTTP would expect ;)
I currently ran into a strange issue where the I can send GET requests from a browser or curl and receive a totally fine 200 OK,
but when I send the very same request from my Android app, the server responds with
Before adding
flask-restx
, the server responded correctly with 200 OK. I do not understand, what causes the 500 Internal Server Error.The Java code used to issue the GET request:
I really can't think of why. So I decided to capture HTTP GET on the host running the server:
From Firefox / Swagger UI
Android (500 Internal Server Error):
Curl (200 OK)
Environment
Python 3.10.5 Flask 2.1.2 Werkzeug 2.1.2 Flask_restx 0.5.1