H18 Error: Django app Media Upload failing on Heroku - django

Our Django App is failing media upload. This has been an off-and-on issue for us for a while. however, for about a week now, it's been consistently failing to upload media. Our media files are stored on S3.
On inspection, the uploaded files were found in the S3 buckets... However, the logs display the message below while the app throws an Application error...

Found this answer on GitHub (https://github.com/benoitc/gunicorn/issues/840)
Hi, we hit this issue in production using Flask + Gunicorn + Heroku and couldn't find a cause or a workaround.
For one particular POST request with POST parameters, the request would fail with an H18 error (sock=backend) in Heroku's router indicating that the server closed the socket when it shouldn't have.
We started decreasing the response size of that failing endpoint until we narrowed it down to around the 13k mark. If we sent less than 13k, the response would always work. If we sent more than 13k, the response would almost always not work.
Code to reproduce this is available at https://github.com/erjiang/gunicorn-issue - just deploy the repo to Heroku as is and follow the instructions in the README.

Related

Intermittent server error when submitting forms using Django

I am getting the following 500 server error when I deploy my Django web application to google app engine:
Error server error the server encountered an error and could not complete your request please try again in 30 seconds
Simply refreshing the page solves this issue and renders the page. However, this isn't ideal and I want the page to load correctly the first time tried. This error does not occur on my localhost, it only occurs on the deployed site and typically during form submissions and rendering detail pages.
I've researched the HTTP status codes in Django extensively from their documentation. It does not matter if the app is set in DEBUG mode or not. The same error appears. This is happening for both GET and POST requests. I have also tried to use a try-except block to retry the request multiple times before accepting failure.
My configuration:
Django: 3.2.9
Browser: Chrome 98.0.4758.80
Simply needed to upgrade my google app engine tier to a more professional level. Nothing was wrong, I just outgrew my tier and it just needed more computing power.

The page at https://lyrics-chords.herokuapp.com/ was not allowed to display insecure content from http://localhost:8000/auth/user

I've just finished creating a Django-React app and have pushed the changes to Heroku. The frontend (JS and CSS) appear on the website no problem, but requests to the backend result in the following error:
[blocked] The page at https://lyrics-chords.herokuapp.com/ was not allowed to display insecure content from http://localhost:8000/auth/user
I've consulted the Internet but no one seems to be getting the same error message. Consulting a friend, it seems as if I have to https secure my backend, and futher researching the subject, it seems that there is no free way to upload a SSL/TSL certificate (reference: heroku: set SSL certificates on Free Plan?). Is there a solution to this?
Silly me, really. Turns out, localhost:8000 refers to the computer of the user. https://lyrics-chords.herokuapp.com/ is the server for both the backend and frontend, so updating the backend end URL calls sufficed.

Status 500 for POST requests in django on IIS

Dear StackOverflow community, your help would be greatly appreciated.
I have zero experience with IIS. Unfortunately, a Windows Server 2012 with IIS 8.5 is all I can get for the current project. I followed this post by Matt Woodward to get my Django app running on IIS. I serve static files by means of an application that references the static folder. The app looks the way it is supposed to look and all GET requests are processed properly. However, the response to all POST requests (on localhost and remotely) is Status 500 Server Error. If I run my Django app with the runserver command, the POST requests are processed properly.
POST is NOT blocked in IIS Request Filtering -> HTTP Verbs. POST requests are sent to URLs like http:/site_title/update_plan/, not to html. The StackOverflow posts found here and here were not helpful.
I suspect the problem is in the IIS settings, but maybe some special Django settings are required and I am missing it. Any ideas on what can be done to fix the problem would be of great help. Thanks!

Cloudinary direct unsigned upload with django

I am using the cloudinary sample django project:
https://github.com/cloudinary/cloudinary-django-sample
I made the following changes:
- using django 1.8.6
- using cloudinary 1.4.0
- added CLOUDINARY_URL environment variable
- added cloudinary_cors.html file (provided by cloudinary) in static/html directory
I can perform server-side upload and everything works fine.
When I perform browser upload (signed or unsigned), the image selected uploads to my cloudinary account successfully, but the cloudinarydone event never occurs and the browser doesn't resister a successful upload.
Instead, I am getting this error in the browser console:
XMLHttpRequest cannot load https://api.cloudinary.com/v1_1/[namespace]/auto/upload. The request was redirected to 'localhost:8000/static/html/cloudinary_cors.html?bytes=4304&created_a…s=%23%3CSet%3A0x0000000ab0e050%3E&type=upload&version=[num]&width=402', which is disallowed for cross-origin requests that require preflight.
I would think the POST doesn't require a preflight CORS request. I have seen other posts online about the preflight error, and it seems some of them were resolved by fixing javascript imports. My order is:
1. jQuery
2. uiwidget
3. iframe-transport
4. fileUpload
5. cloudinary.js
which seems correct based on said posts.
What am I doing wrong? What do I need to change to get the cloudinarydone event?
we're working on a fix for this issue.
Meantime, in upload.html you should replace the following line:
.fileupload({
with
.cloudinary_fileupload({
This should solve the issue for you.

Azure Web Site with Django 500 Error

I've spent over 8 hours trying to get this Django site up and running on an Azure Website. I've nearly thrown in the towel would really appreciate some help.
So far I have tried numerous methods and followed different tutorials, but they have all yielded the same result. Here is the most recent tutorial I have followed: http://www.windowsazure.com/en-us/develop/python/tutorials/web-sites-with-django/
Now that my site is "up", I am seeing a 500 error for all requests. Here is the error in the log:
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during
the processing of the request. The root cause of this error depends on which mo
dule handles the request and what was happening in the worker process when this
error occurred. IIS was not able to access the web.config file for t
he Web site or application. This can occur if the NTFS permissions are set incor
rectly. IIS was not able to process configuration for the Web site o
r application. The authenticated user does not have permission to u
se this DLL. The request is mapped to a managed handler but the .
NET Extensibility Feature is not installed.
Things you can try:
Ensure that the NTFS permissions for the web.config file are correct
and allow access to the Web server's machine account. Check the ev
ent logs to see if any additional information was logged. Verify the p
ermissions for the DLL. Install the .NET Extensibility feature if th
e request is mapped to a managed handler. Create a tracing rule to tra
ck failed requests for this HTTP status code. For more information about creatin
g a tracing rule for failed requests, click here.
Please help!
I got it working by settings up a new django project from the azure gallery and changed some configs and such.
Edit: The configs I updated was just the name of my app. In my case I also updated the database config with the database I wanted to use in settings.py.
The lesson learned from this is that it is easier to initialize the app from Azure's "Create from gallery" feature, and then pull down the source and modify it via ftp or git to achieve the desired project structure/naming.