I recently upgraded from django 1.11 to django 3.0.
Currently, when i launch python manage.py test, django logs any bad or unauthorized requests from my tests, the fact is : it did not log such while on 1.11
Exemple :
.2021-01-06 18:04:20,374 Unauthorized: /api/image/create
..2021-01-06 18:04:20,426 Bad Request: /api/image/transfer/create
.2021-01-06 18:04:20,436 Bad Request: /api/image/transfer/create
...
----------------------------------------------------------------------
Ran 3 tests in 0.008s
OK
Preserving test database for alias 'default'...
Did i miss something while reading django changelog ?
I'd like some light because i do not want to make a distribution without knowing if it's only warning or real error.
Since django 2.1, they added logging to error 4xx and 5xx :
https://github.com/django/django/commit/10b44e45256ddda4258ae032b8d4725a3e3284e6
Just do before launching test :
import logging
logger = logging.getLogger('django.request')
logger.setLevel(logging.ERROR)
or create a decorator for each test you want to silence.
Related
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.
I deployed an web app which django restframework base on Heroku and Azure.
Same app on Heroku works fine.
But when I access to Azure, it causes ERR_TOO_MANY_REDIRECT error.
I googled and found that turn SECURE_SSL_REDIRECT off solved ERR_TOO_MANY_REDIRECT error.
However, it causes 403 CSRF error instead.
I need to find another way to fix ERR_TOO_MANY_REDIRECT or find a way to fix 403 CSRF error.
Can anyone help me to solve this issue?
If your app is on "Azure App Service", the HTTPS connection will be terminated before it reaches your web worker. Your app wil see an incoming HTTP request instead. In this case you need to set SECURE_SSL_REDIRECT = False indeed. If you want to enforce HTTPS (which is a good practice) you can do so in the Azure settings: https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-bindings#enforce-https
About the CSRF-related error: because Azure translates HTTPS to HTTP, you need to configure Django to allow POST requests from a different scheme (since Django 4.0) by adding this to settings.py:
CSRF_TRUSTED_ORIGINS = ["https://YOUR-DOMAIN.com", "https://www.YOUR-DOMAIN.com"]
If this does not solve your problem, you can temporarily set DEBUG = True in production and try again. On the error page, you will see a "Reason given for failure" that you can post here.
I am trying to deploy my Django rest framework to aws eb but when I test the API, it shows
favicon.ico:1 GET
http://myapp.....com/favicon.ico
500 (Internal Server Error)
I update my url.py of django project to
from django.views.generic.base import RedirectView
urlpatterns = [
url('favicon.ico', RedirectView.as_view(
url='/static/favicon/favicon.ico'))...]
But It still shows an internal error.
I already search and found similar questions but not a useful answer.
like that=>
How do I edit the favicon in the browsable API in Django rest framework
how to handle favicon request in Django rest framework
My API is pretty separate from the frontend so I can't change frontend for this error.
Update
If I test on local like =>
http://127.0.0.1:8000/favicon.ico
it gets the same result with =>
http://127.0.0.1:8000/api/
I am troubleshooting a Django app.
Recently the app seems to Randomly generate CSRF verification errors:
CSRF verification failed. Request aborted.
(Resulting in a 403)
Where can I find detailed information on the cause of the verification failure?
The error you're seeing is on the client side - which won't by default know what's going wrong on your server unless you have set DEBUG = True (which you don't want to do in production).
If it was replicable on your staging server it would be easy to fix, since you could replicate the error with DEBUG = True on staging and quickly see where the verification fails in Django's csrf.py.
What you're looking for is the output of which of these error is occurring on your server.
If you implement logging in Django you'll be able to investigate and determine which of these errors was triggered on your production site. A service like Sentry makes this even simpler since it will send you the traceback anytime an error happens.
We're using django 1.2.7 and the hoptoad logging middleware (hoptoad.middleware.HoptoadNotifierMiddleware).
When an error occurs, the error message gets sent to airbrake, but it does not seem to get logged to the django log file. It seems like it's intercepted by hoptoad exclusively.
Does anyone know how to also get the errors logged to the local django log file on disk? I couldn't find any such option in the hoptoad documentation.
Is there a custom modification needed to the hoptoad middleware class?