Request Timeout in flask (408 Status Code) - python

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.

Related

Getting Error 400 when sending GET request with json field from one Cloud Run to another

I am trying to send a request from one Cloud Run service to another. Both are running on Flask. My issue is that there is an email field that I need to send as part of the body of both PUT and GET requests. I know GET doesn't usually have a body but I need to send it this way. However I keep getting an Error 400 (Bad Request). It works fine when I run the services on my local machine but this error starts to appear when on Cloud Run. Please help me figure out if there is a configuration or something I can change to get this to work.
#bigbox_routing_bp.route("/variants/", methods=["GET"])
#secure(
scope=UserAccountType.INTERNAL,
resource_type=ResourceType.VARIANT,
permissions=[ProductPermissions.ALL, ProductPermissions.READ],
)
def get_variants():
regexMatch = re.match(f"(.*)({request.path})(.*)", request.url)
response = requests.get(
url=f"{BIGBOX_URL}{regexMatch.group(2)}{regexMatch.group(3)}",
json={"email": request.user.email},
)
return (response.json(), response.status_code)

With Bottle, how could I just peek the head of http request instead of receiving whole http request?

I don't know if it is possible with Bottle.
My website (powered by Bottle) allow users to upload image files. But I limited the size of it to 100K. I use the following code in web server to do that.
uploadLimit = 100 # 100k
uploadLimitInByte = uploadLimit* 2**10
print("before call request.headers.get('Content-Length')")
contentLen = request.headers.get('Content-Length')
if contentLen:
contentLen = int(contentLen)
if contentLen > uploadLimitInByte:
return HTTPResponse('upload limit is 100K')
But when I clicked upload button in web browser to upload a file with its size like 2MB, it seems the server is receiving the whole 2MB http request.
I expect the above code just receive http headers instead of receiving whole http request. That could not prevent wasting time on receving unecessary bytes

Flask Error: 414 Request-URI Too Large

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?

Using cherrypy for HTTP and HTTPS

I set up an http(s) upload server using cherrypy for uploading something with a blackberry application. I use this code to send data to the server but I always get a bad request (400) error. It gives no other debug info or anything to help. Any ideas abut what may be wrong or what can I do to learn more about the problem ?
This error line is like this:
{My IP} - - [16/Nov/2012:11:35:32] "POST /upload HTTP/1.1" 400 1225 "" ""
If the server only returns 400-something messages, without any additional information, you can either set the 'engine.autoreload_on' config option to True, which should give you the detailed error messages + tracebacks when something goes wrong. Another option would be to specify filenames for log.access_file and log.error_file to redirect their output to specific files.

App engine Channel API returns no messages

Problem description: channel messages no returned to ajax script.
Initially, messages are delivered to clietn side, but the problem appears when I set larger timeout in js:
goog.appengine.Socket.POLLING_TIMEOUT_MS = 5000; //poll every 5 seconds
I've added a very basic Python code to test if Channel API works in my Google App Engine app.
index:
token = channel.create_channel(CHANNEL_NAME)
channel.send_message(CHANNEL_NAME, message)
#token is passed to template
additional_view:
#is another view, trigger manually from browser after index
from django.utils import simplejson
channel.send_message(CHANNEL_NAME, simplejson.dumps(data))
At client side I have a regular js with onMessage code.
The problem is that no messages are returned to client-side requests. They all come empty to polling ajax (as seen in Firebug). In application log I can see that channel is created:
"Creating channel token channel-2382918168-broadcast with client id broadcast"
and later message is sent but with a comment:
in between come these requests:
INFO 2011-08-03 14:33:32,000 dev_appserver.py:4248] "POST /_ah/channel/connected/ HTTP/1.1" 404 -
INFO 2011-08-03 14:33:33,780 dev_appserver.py:4248] "POST /_ah/channel/disconnected/ HTTP/1.1" 404 -
** ....message text...to channel with key (broadcast): no clients connected***
How does channel/message function at deeper level? Are messages lost if no clients are connected or they are retrived by newly connect clients?
If for some reason I create a channel with the same name, would it distroy undelivered messages it has inside?
Stay away from setting the POLLING_TIMEOUT_MS higher than 1.5 sec, the dev_appserver will assume you have disconnected.
It does not work via polling in production, so you do not have to worry about the timeout really.
Edit: just saw Robert's comment; personally I have even had issues if I set the polling to 3sec in Chrome/Safari/Firefox. I now just have ?disable_channel=true query strings on my apps so that I can run them without setting my laptop on fire with the CPU usage.

Categories