Flask Error: 414 Request-URI Too Large - python

I'm using Flask with Apache. When I send a GET request with a long url (19000+ characters), the response is
Status 414: Request-URI Too Large.
I suspect that the request triggers a werkzeug RequestURITooLarge Exception or a flask HTTPException. When I send a request with similar url length to Apache directly there is no error.
Is there a way to increase the maximum url length that Flask handles?

You can use POST instead of GET, but if you don't need to use it i think this question have related answer for your problem.
How do I resolve a HTTP 414 "Request URI too long" error?

Related

Flask App deployed on Heroku returns error on post requests

I deployed my Flask App on Heroku, I noticed that once deployed post request in the API don't work anymore and the app just responds with status code 400 and "message": "The browser (or proxy) sent a request that this server could not understand.". Get requests work normally but post don't. Also I am quite confused because if I run the app on localhost everything works as expected but not once deployed. Anyone knows how to solve?
To parse request argument I use args = ParseArgs.parse_args() from flask_restful and I retrive the value with:
args = ParseArgs.parse_args()
mode = args['Mode']
value = args['Value']
I tried to look up on google and I saw that it might be the Content-Type header with value application/json, I removed it but the problem still persists.

Rest api of gerrit gives the response but Python-gerrit-api package for fetching revisions gives status 404

Documentation: https://python-gerrit-api.readthedocs.io/en/latest/
Code
gerrit = GerritClient(base_url="https://gerrit.xx.com",username='xxx',password='xxx')
change = gerrit.changes.get("xxx")
ab=change.get_revision("32423")
print(ab.get_commit().list_change_files())
Question
For some endpoints, I am able to send get responses from the rest api but via this package I get this error(gerrit.utils.exceptions.NotFoundError: 404 Client Error). I am able to get response from Get Rest api for this url: gerrit.xx.xx.com/a/projects/xxxx/commits/xxxx/files via postman. But error with above code.
Looks like this is a bug, I have fixed it and made a pull request. See: https://github.com/shijl0925/python-gerrit-api/pull/5

Request Timeout in flask (408 Status Code)

i've received request timeout after 20 sec when upload file and "werkzeug.exceptions.ClientDisconnected: 400 Bad Request" error in server side when using request.files!
this code working correctly for less than 20 sec!
i found a solution, i use dropzone and chunking file.

WSO2 API POST Python Web Service - Empty or No Payload to server

I am not able to send request payload to my POST service from WSO2.
On rest console, my service is working.
From WSO2 server I am able to do curl to my server with successful response.
here is my API configuration
Payload to send:
{"query":"Hi I am a POST query parameter"}
My server is receiving {} as request payload. It expect RAW body in JSON (as above) in payload. I have tried all combinations for Parameter Type, but still not able to send payload to my server from WSO2.
How can I do this?
EDIT 1
I have tried all possible ways of sending data including following.
Am I doing something wrong here???
and
From both I get error that my payload is empty or incorrect!!
Edit 2
I am able to connect with Java based services but not with Python based services.
Do I need any special settings on my python server?
enable wirelogs and check following
payload is coming into the API manager (swagger -> AM )
Payload is going out from api manager (AM -> backend)
Also check the request headers coming in and going out and compare them with the stuff from curl request (successful request)
I am using Flask and I am afraid Flask can not deal with this issue currently.
I could reproduce this issue, the message send to back-end correctly, but Python only handle message until timeout.
Python Flask cannot receive post request from WSO2
The work-round may be using Java or Python get method.
I solved this problem by using apache to proxy this request.
I think this is related with wsgi.
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
ProxyPass / http://localhost:8001/
ProxyPassReverse / http://localhost:8001/

Getting warning and error at same time in tornado proxy

It seems like i am hitting some race condition in between the time I stop my server and during that I make request through tornado proxy frontend.
I get very famous error
WARNING:tornado.access:404 POST /request-url/eff74/36eb5e9f-def1-4689-ad58-3bf866798864/client-update (::1) 0.88ms
ERROR:tornado.general:Cannot send error response after headers written
WARNING:tornado.access:404 POST /request-url/eff74/36eb5e9f-def1-4689-ad58-3bf866798864/client-update (::1) 1.36ms
ERROR:tornado.general:Cannot send error response after headers written
WARNING:tornado.access:404 POST /request-url/eff74/36eb5e9f-def1-4689-
which is described in source code here
Can I resolve this problem?
Point of confusion is I am getting 404 already, then why I am getting an error after wards.
Cheers
Actually, it was very silly bug in my code.
Bug was the proxy function which was handling "requests" wasn't issuing "return" statement from the function.
Example:
def proxy_handler(self, request, response):
# some task
response.set_status(status_code)
response.send("status_code: message")
return # this was missing earlier
So tornado was trying to send respons which already has been sent. Thus getting the error
WARNING:tornado.access:404 POST /request-url/eff74/36eb5e9f-def1-4689-ad58-3bf866798864/client-update (::1) 1.36ms
ERROR:tornado.general:Cannot send error response after headers written
Cheers

Categories