The logs of POST/GET requests from Django application on Apache - django

Django development server is really nice, it shows the log of all POST/GET requests as well as other events in real time. Example of logs from Django dev server:
[04/Jul/2012 19:23:27] "GET /static/images/sprites/submit_url_hover.png HTTP/1.1" 200 7088
[04/Jul/2012 19:23:42] "POST /validate_link HTTP/1.1" 200 0
[04/Jul/2012 19:23:44] "POST /download_link HTTP/1.1" 200 0
It's very useful for debugging, figuring out the sources of 500 errors, etc. I've recently deployed my Django app on Apache and looking for logs analogous to that of Django Dev Server on Apache. There is obviously Apache error logs (snippet is below):
[Wed Jul 04 18:37:45 2012] [error] [u'microsoft', u'design', u'logos']
[Wed Jul 04 23:51:01 2012] [error] [client 140.180.6.212] File does not exist: /srv/my_project/app/portnoy/site_media/favicon.ico
But that's not what I want. My site has a simple link submission functionality which works locally (on Django dev server), but is not working on the actual site (running Apache). So seeing the Django dev server style logs on Apache will be really helpful. Any idea where can I look at? Thank in advance and happy 4th!

Check access.log for the apache where you will see each request processed and response sent.
Also, if you have not tried yet, set DEBUG=True in your settings file so django will show you detail error, trace and other useful information.

Related

Django - Stripe API Integration Error - Could not verify Stripe's SSL certificate

So, testing in development worked accordingly, but moving to production yields the issue described in the title. I have contacted Stripe and they appear to be neglecting the problem.
The issue is intermittent, as if I refresh the page a few times, I can cause the error. It appears to be random.
I am using Heroku to run a multi-tenant app with Django. Heroku-18 stack.
I have a wildcard cert.
TLS version is 1.2
OpenSSL version is 1.1.1
Python version 3.6.10
Stripe version 2.41.1 (installed through pip and API version is up-to-date as well)
Error Log
Jan 13 21:58:36 app/web.1: raise error.APIConnectionError(msg, should_retry=should_retry)
Jan 13 21:58:36 app/web.1: stripe.error.APIConnectionError: Could not verify Stripe's SSL certificate. Please make sure that your
Jan 13 21:58:36 app/web.1: network is not intercepting certificates. If this problem persists,
Jan 13 21:58:36 app/web.1: let us know at support#stripe.com.
In addition to these problems, the webhook I have fails from a 301 redirect. Not sure how my site is being redirected, but all instances of my webhook fail trying to connect to my site.
Honestly I am so stuck, so let me know if you need additional information to further help me.

localhost:8000 working but mywebsite:8000 with etc/hosts modified doesn't work

Everything is in the title: I'm launching my webserver (Django / Python) on port 8000.
/home/olivier/my_venv3.8/bin/python3 /home/olivier/pycharm-2018.1.3/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 40761 --file /home/olivier/projects/evalr/manage.py runserver 8000
pydev debugger: process 5923 is connecting
Connected to pydev debugger (build 193.5662.61)
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
pydev debugger: process 5935 is connecting
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
Watching for file changes with StatReloader
Performing system checks...
I've added in my /etc/hosts this line : 127.0.1.1 evalr.hqf.fr and when I ping it, it correctly shows "127.0.0.1"
When I try go on http://evalr.hqf.fr:8000 I get connection refused and when I try to go on http:/localhost:8000 it works.
The problem is that when I try to go on http://evalr.hqf.fr:8000 I dont have any trace on the server side, i.e. it stays here:
System check identified no issues (0 silenced).
January 03, 2020 - 20:41:31
Django version 3.0.2, using settings 'evalr.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
And when I go on http://127.0.0.1:8000/ I get a log of every single access like:
[03/Jan/2020 20:47:42] "GET /fr/sessions/ HTTP/1.1" 302 0
[03/Jan/2020 20:47:42] "GET /fr/login/?next=/fr/sessions/ HTTP/1.1" 200 7031
[03/Jan/2020 20:47:43] "GET /static/vendors/css/all.min.css HTTP/1.1" 200 54456
................ blabla............;
[03/Jan/2020 20:47:43] "GET /favicon.ico HTTP/1.1" 301 0
I've even tried to reboot (even though I'm on Linux, which talks by itself - no reboot needed), so I'm stuck because everything should work fine. What am I missing?
That is because in /etc/hosts it should be 127.0.0.1 instead
Also check the ALLOWED_HOSTS and you could try running it with: python manage.py runserver 0.0.0.0:8000
The fact that you get a connection refused when using the hostname, and do not see any logging from your application, makes me think that you are dealing with DNS caching. My favorite way to test this is using curl, since it can show you both the IP address and response of an HTTP request. Try the following command:
curl -Iv -X GET http://evalr.hqf.fr:8000
Did it resolve to 127.0.0.1? If so, did you get a response? If so, did you see logs in your application?
If the answer to these question is yes, then try to clear the DNS and browser cache.

ngrok doesn't lift my local django web server

I have problems with negrok, it does not raise my local django web server, a few days ago everything worked correctly but a normal day, without having touched anything, it stopped working.
Run the following:
python manage.py runserver
Everything works normally and correctly.
Now I execute the following, in order to raise the local django server:
./ngrok http 8000
ngrok runs correctly without any problem but when accessing the ngrok link, the page is loading and everything is blank and does not work ....
This appears in ngrok:
ngrok by #inconshreveable (Ctrl+C to quit)
Session Status online
Account Julio (Plan: Free)
Version 2.3.34
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://33822c5a.ngrok.io -> http://localhost:8000
Forwarding https://33822c5a.ngrok.io -> http://localhost:8000
Connections ttl opn rt1 rt5 p50 p90
2 0 0.03 0.01 0.20 0.21
HTTP Requests
-------------
GET / 400 Bad Request
GET / 400 Bad Request
And this appears in django:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
September 25, 2019 - 17:23:19
Django version 2.2.2, using settings 'ibme_proyect.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Invalid HTTP_HOST header: '33822c5a.ngrok.io'. You may need to add '33822c5a.ngrok.io' to ALLOWED_HOSTS.
Bad Request: /
[25/Sep/2019 17:25:30] "GET / HTTP/1.1" 400 68119
Invalid HTTP_HOST header: '33822c5a.ngrok.io'. You may need to add '33822c5a.ngrok.io' to ALLOWED_HOSTS.
Bad Request: /
[25/Sep/2019 17:25:38] "GET / HTTP/1.1" 400 68254
I add the ngrok host (33822c5a.ngrok.io) in ALLOWED_HOSTS and stop giving django error, and access the ngrok link and I know that it loads again, it doesn't load the HTML, nothing, everything blank ...
Any solution? :(
try
ALLOWED_HOSTS = ["*"]
this will allow tunneling every ngrok run :)

Nginx Bad Gateway with Django Social Auth and uwsgi

My site is running correctly locally (using the built in runserver), but when running with nginx and uwsgi, I'm getting a Bad Gateway (502) during the django-social-auth redirect.
The relevant nginx error_log:
IPREMOVED - - [11/Oct/2012:12:10:18 +1100] "GET /complete/google/? ..snip .. HTTP/1.1" 502 574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.26 Safari/537.11"
The uwsgi log:
invalid request block size: 4204 (max 4096)...skip
Thu Oct 11 12:16:46 2012 - error parsing request
Refreshing the Bad Gateway response redirects and logs in correctly. This happens every single time. The nginx and uwsgi logs here have different timing as they were separate requests. The logs are consistent.
This is the first time deploying django to nginx for me, so I'm at a loss as to where to start.
Have you tried increasing the size of the uwsgi buffer:
-b 32768
http://comments.gmane.org/gmane.comp.python.wsgi.uwsgi.general/1171

Django + Apache, browser always loading and none data received

I am running Django site in Apache with mod_wsgi.
The site works before. Today when I am try to install a tokuwiki on the same server, I found the site become failed that when I open the django site, the chrome always loading and after a long long time it say "no data received".
The django site works on my development machine and another virtual machine.
On the amazon ec2:
When I use wget on static files (.css, .img) served by apache, it received normally.
But when I use wget on dynamic page from django, it stoped at awaiting response... , which means the problem is on the django + apache part.
I check the apache log that each time I refresh the browser, it will loading the django setting again, but nothing else. The log shows it did not enter the view function (I am not sure whether it entered the url routine or not):
[Sat Nov 19 02:15:54 2011] [error] Absolute_dir: /home/www/jdlab-browser/trunk/jdlab_browser
[Sat Nov 19 02:15:54 2011] [error] Using Amazon Server Settings
[Sat Nov 19 02:15:54 2011] [error] Absolute_dir: /home/www/jdlab-browser/trunk/jdlab_browser
[Sat Nov 19 02:15:54 2011] [error] Using Amazon Server Settings
I tried to uninstall tokuwiki, reinstall apache, mod_wsgi, django. Rewrite the apache configure file.
Other information:
I opened the Debug mode of Django, and when I visit a not exist page, Django's page not found error page showed on the browser.
When I open the django's admin console mysitename/admin/ , browser also did not received any data.
Any clu where to check next?
Finally, found the problem is caused by scipy package.
And then I found a similar problem asked by other people.
using-scipy-stats-stats-in-django-after-deployment