"GET /new_entry/5 HTTP/1.1" 200 466 - django

When I am learning Django,
The console usually hint me:
"GET /new_entry/5 HTTP/1.1" 200 466
What's the purpose of 200 466?

The 200 is the HTTP status code, which means the request completed successfully. The second number is the size of the request in bytes.

Related

Debugging graphql queries in Django

How can I get my GraphQL API to show more query/post data in the console? I'm running a Django app that is powered by GraphQL and served via a react frontend. With regular Django paths I would see something like this in the development server:
[04/Sep/2020 11:53:08] "GET /my_app/2020/09/01/5cc4e7cc-7.png HTTP/1.1" 200 11330
But with GraphQL all I see is this:
[04/Sep/2020 11:53:18] "POST /graphql HTTP/1.1" 200 32
[04/Sep/2020 11:53:18] "POST /graphql HTTP/1.1" 200 2993
[04/Sep/2020 11:53:29] "POST /graphql HTTP/1.1" 200 11635
Any ideas?
I highly suggest checking out Silky. It's a profiling tool that can show you
the request body - that's where you'll find the graphql
speed of the response
all the DB queries sent during your request
(if you set it up) cprofiler for the request

loading admin page after upgrading to django 3.0 crashes dev. server

I upgraded Django from 2.2 to 3.0, Now I can't access admin page.
Every time I access http://127.0.0.1:8000/admin the dev. server quits without any message or error.
If I revert back to Django 2.2 everything works fine.
I did fresh virtualenv and created new project unfortunately, I hit the same wall again the Dev. server quits without any error.
Is this a common issue or do I have any error?
I am using windows 10 64-bit and Pycharm community 2019.2.5
my virtual is:
Package Version
------------------- ----------
asgiref==3.2.3
certifi==2019.11.28
chardet==3.0.4
Django==3.0
djangorestframework==3.10.3
idna==2.8
Pillow==6.2.1
pip==19.3.1
PyJWT==1.7.1
pytz==2019.3
requests==2.22.0
setuptools==42.0.2
six==1.13.0
sqlparse==0.3.0
twilio==6.34.0
urllib3==1.25.7
wheel==0.33.6
Stack trace
System check identified no issues (0 silenced).
December 06, 2019 - 21:59:45
Django version 3.0, using settings 'suhul_prj.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[06/Dec/2019 21:59:56] "GET / HTTP/1.1" 200 16351
[06/Dec/2019 21:59:56] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[06/Dec/2019 22:00:02] "GET /admin HTTP/1.1" 301 0
[06/Dec/2019 22:00:02] "GET /admin/ HTTP/1.1" 302 0
[06/Dec/2019 22:00:02] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[06/Dec/2019 22:00:03] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[06/Dec/2019 22:00:03] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[06/Dec/2019 22:00:03] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[06/Dec/2019 22:00:08] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
(home_venv) C:\Users\Admin\Dropbox\django_projects\suhul_prj>
looks like this problem going back to python and Django versions incompatibility, which caused WSGI segmentation fault, I had the same issue while I was using python 3.7 and with downgrading python to 3.6 it has been solved!
Just want to share my experience solving the same issue.
I used python v3.7 and got this issue. Solved this problem by upgrading to python v3.8 and creating a new venv.
Now my python version FYI:
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Also another post mentioned this issue.

Flask REST API very slow on simple endpoint

I'm using a Flask REST API for my application and I've noticed that when I send requests from outside my own network, it's sometimes very, very slow. Most calls get completed within 150ms, but some take 8 seconds. The database connection is to a MySQL database using DBUtils.PersistentDB
The code for the endpoint:
#app.route("/name", methods=["POST"])
#jwt_refresh_token_required
def get_name_and_company():
user = get_jwt_identity()
response_object = server_functions.get_name_and_company(user)
return response_object
The function it uses:
def get_name_and_company(user):
sql = "SELECT fysios.firstname, fysios.lastname, companies.name FROM
fysios " +\
"INNER JOIN companies ON fysios.companyID = companies.id WHERE fysios.email = %s"
cursor = flask_server.get_db().cursor()
cursor.execute(sql, user)
data = cursor.fetchall()
first_name = data[0]['firstname']
last_name = data[0]['lastname']
company = data[0]['name']
response_object = name_and_company(first_name, last_name, company)
return make_response(jsonify(response_object)), 200
Here are the timestamps on the Flask server (it is the internal dev server, but I am running it with threaded=True):
[08/Mar/2019 22:16:54] "OPTIONS /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "POST /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "OPTIONS /name HTTP/1.1" 200 -
[08/Mar/2019 22:16:58] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:17:05] "POST /name HTTP/1.1" 200 -
As you can see, /name takes a total of 8 seconds and I can't find out why. This call to /name is just an example, it can happen on any of the calls. Is there a way to find out where the Flask application is actually stuck on?
Deploying to AWS Beanstalk solved the problem. I don't know if the limitations of the build-in dev server is to blame, but that's what did it for me.

Django SAML integration

I am using Django 1.9, Python 3, running locally on Docker (for testing)
Trying to integrate django-saml2-auth into my application.
Pretty much followed all the steps in the docs:
1) All installations were successful
2) New URLs were imported above the rest
3) Installed apps includes 'django_saml2_auth'
4) 'SAML2_AUTH' dict was placed in settings (and all attributes were mapped)
5) In the SAML2 identity provider (using OneLogin), the Single-sign-on URL and Audience URI(SP Entity ID) was set to http://127.0.0.1:8000/saml2_auth/acs/
What happens is that when I get to http://127.0.0.1:8000/admin the browser goes into an infinite redirect loop:
...
[02/May/2018 15:43:06] "GET /admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:06] "GET /admin/login/?next=/admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "GET /admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "GET /admin/login/?next=/admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:08] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[02/May/2018 15:43:08] "GET /admin/ HTTP/1.1" 302 0
...
When I disable django-saml2-auth I see that a staff user was created.
In the OneLogin interface I can see that I logged in successfully.
Overriding django_saml2_auth.views.signin(r), where r is a django.core.handlers.wsgi.WSGIRequest, for <WSGIRequest: GET '/admin/login/?next=/admin/'>, and in the request, the user is set to AnonymousUser, COOKIES contain sessionid and csrftoken.
I would expect that a session would start for the user that was created/fetched, and that I will get to an /admin/<whatever> page.
I will appreciate any help in debugging this, thank you!
EDIT: I was able to get it to work by removing AUTHENTICATION_BACKENDS from settings.py- I have 3 other backends that I use. It seems like they conflict with django-saml2-auth.
Is there any way to get django-saml2-auth to work with other backends?
EDIT 2: Will try to integrate django-saml2-pro-auth, which has a backend so will not conflict. I would really appreciate some insight though.
EDIT 3: back to EDIT 2, when I remove all the backends and they don't conflict, the log flow looks like that:
[04/May/2018 15:24:26] "GET /admin/ HTTP/1.1" 302 0
[04/May/2018 15:24:27] "GET /admin/login/?next=/admin/ HTTP/1.1" 302
[04/May/2018 15:26:27] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[04/May/2018 15:26:27] "GET /admin/ HTTP/1.1" 200 38398
Where the last GET does not get redirected, with 200.
Issue resolved:
After taking a deeper dive- it seems like this code is the issue:
In django_saml2_auth/views.py, acs():
if target_user.is_active:
target_user.backend = 'django.contrib.auth.backends.ModelBackend'
login(r, target_user)
else:
return HttpResponseRedirect(get_reverse([denied, 'denied', 'django_saml2_auth:denied']))
It seems like the default ModelBackend is necessary.
When other backends are used, the default is no longer used by Django, and hence the infinite loop.
If the default backend is added to the list of backends, everything works as intended.

Django development server messages - what do they mean?

If I run a Django development server and view my application in a browser, I get messages like this:
[08/Jan/2011 18:12:45] "GET / HTTP/1.1" 200 2714
[08/Jan/2011 18:12:45] "GET /static/style.css" 200 2714
[08/Jan/2011 18:12:45] "GET /content.html" 200 269
...
What does the last number on each line mean?
(I know that the number one before last is standard HTTP status message, but don't know what the following number represents)
It's the number of bytes sent, see django/core/servers/basehttp.py:
self.request_handler.log_request(self.status.split(' ',1)[0], self.bytes_sent)