Python Script Nor Running In PythonAnywhere - python

I am working on a Django project. It includes a functionality in which when admin clicks on a certain button, it runs a Python script and redirect it to some other page after complete process. Before hosting, it was working fine. Now that I hosted it here, the script doesn't run at all. It just redirects to another page without providing any error. Why's that? Also, my script includes chromedriver, in case it has anything to do with it.
Kindly help me.
This might be the error. Why doesn't it recognize it?
Code
out = run([sys.executable, '//home//maisum279//traffic//traffic//trafficapp//traffic.py', "--domain", url, "--threads", '5', "--max-clicks", maximum, "--min-clicks", minimum, "--stay", stay, "--requests", requests])
Server Log
2020-09-21 11:05:02 /usr/local/bin/uwsgi: unrecognized option '--domain'
2020-09-21 11:05:02 getopt_long() error
The script is in Python, but now it seems to be running with uswgi. What can I do make it work? Please help.

Since PythonAnywhere is apparently running things with uWSGI, which embeds Python, sys.executable is uwsgi and not python3.
You may want to try e.g. ['/usr/bin/env', 'python3', ...] instead of relying on sys.executable.

Related

Django show exception in webpage instead of on console

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.

VS Code not identifying any changes made to the code:

Any changes I make to my code aren't doing anything. I am using three things html, flask and python. Any code change I make to my python or html code is not getting implemented on the browser when I am trying to run it.IT is only running older version of the code.
How can I rectify this error of vscode?
Make sure you're refreshing the page if you're opening a HTML file. If you're accessing the python server make sure to restart it every time you make changes to the code. The way to do it is ctrl+c in the terminal and running the command again. There are ways to make this happen automatically, refer here for more information
Did you start your flask server in debug mode?
from Python
app.run(debug=True)
or from terminal
$ export FLASK_DEBUG=1
$ flask run
Try to run in incognito once. Or try after clearing cache.

Executing a curl command on the client side

Let us say that I am running on a Debian machine a server with sudo python3 -m http.server. Are there possibilities to execute some curl command on the client-side if he opens the website?
My idea is to provide an installation page for my program, so if the user opens it (http://127.0.0.1/install), the commands would be automatically executed in the background. I am aware that there are security reasons why this shouldn't be possible, but let's say the user is okay with it. :)
I have found online something about cgi python scripts, but I never found any example to do what I want and that is why I am not really sure if it is the right thing or not.

How to install and run python script on Microsoft server

Guys and ladies. I am new to programming. I have written some script.It just checks whether some data is correct or not. I want that script to run 24*7 on Microsoft server at job (not on my PC). Please let me know how to do that.
thanks in advance
Aside from general server set-up, you will just need to download Python like you would on any server.
As for the running, something like python yourScript.py would work fine. In order to run it 24/7, you need to put your entire script in a while(True): loop so that it never stops running. Note that you should also include some DECENT error handling in the event on an issue so that it doesn't just crash.

Localhost has stopped updating when various flask/python scripts are run, how do I fix this?

I've been testing out a few .py files with Flask, referring to 127.0.0.1:5000 frequently to see if they're interfacing correctly with the HTML, after running the .py I'm getting the following as normal:
* Running on http://127.0.0.1:5000/
* Restarting with reloader
However, 127.0.0.1:5000 has suddenly stopped updating when scripts are run, remaining as it was after the first time a script was run since my computer has been turned on (restarting the machine is the only way I've found to take a fresh look at my work). To confirm that it's not an issue within .py files or my templates, Flask's hello world example with app.run(debug=True) does not update this localhost page when run. Is there any way to remedy this?
Two things that may or may not be involved with this issue:
(1) I am not using virtualenv but simply running .py files from folder directories on my desktop (following proper format for Flask and the template engine, though). (2) Around the time the problem started I installed SQLAlchemy and its Flash extension, Flask-SQLAlchemy with pip.
After tracking the processes down by running $ netstat -a -o in the command line, it turns out it wasn't a code error, but rather multiple instances of pythonw.exe, which can be taken care of in the Task Manager. I'm not sure why the processes keep running after I close out of all python windows, or why it keeps communicating with 127.0.0.1:5000, however, so thoughts on this would still be appreciated.
Thats right. Just press 'Ctrl+Shift+Esc' to open the task manager.
Scroll down to find the 'python3.exe' files and end the task manually.
The reason is 'ctrl+c' doesnt work for me (it just copies the text on terminal window), so I have to manually kill the python interpreter running in the background. Its hard work, but hey atleast you dont have to restart your computer everytime!!

Categories

Resources