I am launching a Django API from the console via the following command line:
python3.10 manage.py runserver 0.0.0.0:8080
However, sometimes, when there is an error on one of the pages, like for instance if I import a python package that was not installed via pip, the webserver does not get launched, I get a python exception on the console, but no webserver is launched (the network port is not even listening).
Is there a way to still have the webserver running and showing any exceptions or errors that might arise ? This API is for learning purposes, the students should only be able to deploy their code by doing a git push and the new code is deployed. But in case of an error that is not shown in the webpages they would not know what went wrong, they do not have access to the server to see the console.
Thank you for your help.
Related
I'm currently attempting to make a Jira plugin that contains a Java servlet that calls my Python script with ProcessBuilder to do some frontend work, which works perfectly on localhost.
Except, whenever I deploy it onto the online Jira server, my python script doesn't get called and hence the HTML isn't updated. I've deduced that it is most likely because the plugin or machine running the Jira server responsible for calling my script probably doesn't have anything in it to execute python.
As a result, I've tried to do some process builder things and install Python onto the server, to no avail. I found out that the system running the server is a Linux machine and have tried to "sudo apt-get install python" and even tried to just run python3 myscript.py to no avail. It keeps erroring out and throwing me a NullPointerException whenever I start any process that has to do with installing Python.
Anyone have any ideas?
I'm actually learning to use the Django framework with PostgreSQL with Docker and docker-compose.
Regularly, when I make a mistake (for example a syntax error in the views.py file), I cannot reach my Django app anymore trough my web browser.
Firefox tells me:
Unable to connect
Firefox can't establish a connection to the server at localhost:8000
Chrome tells me:
This site can’t be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED
I had this several times and I always managed to find the error in my code, to correct it and then everything went well again.
Currently, my code is working fine. But if I encounter this again (and this happens very often), I would like to be able to find the error quickly by myself.
So here is my question:
How can I see which file at which line contains the error ?
I would like to have a correct error message telling me what went wrong instead of that annoying ERR_CONNECTION_REFUSED browser page over and over.
I hope I explained my issue well because I struggled to describe it to Google.
Thanks a lot in advance. :)
FYI:
Ubuntu 18.04.3 LTS Bionic (window manager i3wm)
Docker 19.03.4
docker-compose 1.17.1
python 3.7 (docker image)
Django 2.2.6 (inside the python 3.7 image)
PostgreSQL 12.0 (docker image)
Visual Studio Code 1.39.2
I finally found a solution.
I had the bad habit to run my docker-compose in detached mode.
When attached, the syntax errors are shown directly from the terminal when de container is stopped.
I also added a script where I run my server in a loop. This way, the server will relaunch automatically over and over until I correct the error. I don't have to restart my Django server manually.
Thank you for helping me anyway.
I'm maintaining a web application built with Flask with python 2.7 coupled with Jinja and angularjs .In a Linux environment, everything is working fine.
On windows when I run the application on cmd or git bash (python app.py), I only see that the server is running and in which port (and everything else is working fine in the browser), but the problem is that the logs in console aren't shown like in a Linux terminal.
For example, I can't see the requests like: POST /login..or an exceptional mission or even a simple print "test" Dosen"to show (still everything is working in a browser).
Even worst, when I terminate the server with "ctr+c" all the previous messages and logs are printed in the terminal, all together in one single dump!
--- Update ---
when i use the command python -u app.py
it's even worst , the application dose'nt run in the browser anymore , no log in console and when i termiante it shows this :
screenshot of terminal
I would suggest that you creat a proper uWSGI gateway.
An example setup could be:
Linux 18.04 ->
Nginx / Apache reverse web proxy mode ->
Gunicorn (which has a debugger you can attach, this will output to the regular log files like other applications. Systemd logs I think) ->
Flask web framework.
Hope this helps.
I'm getting the below error when trying to run the command heroku run python manage.py migrate from the terminal.
ECONNRESET: read ECONNRESET
I followed the link in the heroku docs to check if there was a firewall issue, but I had a successful telnet connection. I haven't been able to find any other examples of anyone running into this issue unless they are having a proxy/firewall issue but according to the telnet test it doesn't seem like I have a problem right?
I've also tried testing any other heroku run command I can think of and I get the same result.
After reading the logs it showed that there was an Error Code R13. I was able to follow this thread to get what I needed to be fixed but was unable to run anything that needs to actually be attached (like an interactive shell).
Tried filing something with Heroku support but they basically said that it's outside the scope of free support. Disappointing.
The problem is related with a proxy in your internet connection.
Try to connect to heroku by using another internet connection, for example your mobile phone tethering.
It worked for me.
The problem is as a result of your internet connection provider blocking Heroku server. Change the source or provider of your internet and you will be able to connect to the Heroku Django console.
To debug a bug I'm seeing on Heroku but not on my local machine, I'm trying to do step-through debugging.
The typical import pdb; pdb.set_trace() approach doesn't work with Heroku since you don't have access to a console connected to your app, but apparently you can use rpdb, a "remote" version of pdb.
So I've installed rpdb, added import rpdb; rpdb.set_trace() at the appropriate spot. When I make a request that hits the rpdb line, the app hangs as expected and I see the following in my heroku log:
pdb is running on 3d0c9fdd-c18a-4cc2-8466-da6671a72cbc:4444
Ok, so how to connect to the pdb that is running? I've tried heroku run nc 3d0c9fdd-c18a-4cc2-8466-da6671a72cbc 4444 to try to connect to the named host from within heroku's system, but that just immediately exits with status 1 and no error message.
So my specific question is: how do I now connect to this remote pdb?
The general related question is: is this even the right way for this sort of interactive debugging of an app running on Heroku? Is there a better way?
NOTE RE CELERY: Note, I've now also tried a similar approach with Celery, to no avail. The default host celery's rdb (remote pdb wrapper) uses is localhost, which you can't get to when it's Heroku. I've tried using the CELERY_RDB_HOST environment variable to the domain of the website that is being hosted on Heroku, but that gives a "Cannot assign requested address" error. So it's the same basic issue -- how to connect to the remote pdb instance that's running on Heroku?
In answer to your second question, I do it differently depending on the type of error (browser-side, backend, or view). For backend and view testing (unittests), will something like this work for you?
$ heroku run --app=your-app "python manage.py shell --settings=settings.production"
Then debug-away within ipython:
>>> %run -d script_to_run_unittests.py
Even if you aren't running a django app you could just run the debugger as a command line option to ipython so that any python errors will drop you to the debugger:
$ heroku run --app=your-app "ipython --pdb"
Front-end testing is a whole different ballgame where you should look into tools like selenium. I think there's also a "salad" test suite module that makes front end tests easier to write. Writing a test that breaks is the first step in debugging (or so I'm told ;).
If the bug looks simple, you can always do the old "print and run" with something like
import logging
logger = logging.getLogger(__file__)
logger.warn('here be bugs')`
and review your log files with getsentry.com or an equivalent monitoring tool or just:
heroku logs --tail