My python script executes fine in Jail shell, putting out html which I can pipe to an html file. When I look at the file, it's exactly what I want. However when I try to run the file from a browser I get a 500 error. According to the instructions at http://imgseekweb.sourceforge.net/install.html the cgi-bin should be in suEXEC mode. My hosting company changed the cgi-script handler to allow .py files and he made a little test script that works fine, but mine still does not.
I tried to make suEXEC a custom Apache file handler of .py files in cPanel, but this did not seem to help, it just made the Python script print out as text in the browser without executing.
Any ideas for resolution. I'm so close now that script at least works in Jail Shell. I even try to fake out Apache by making the test file launch a system execution of the python script but that also caused a 500 error, although it too spit out the correct html in Jail Shell even doing some Lynx like display of the html this time.
Whatever machinations I did also caused the test.py to stop working. It now gives a 500 error too even with all the code I added removed.
My hoster resolved the issue. It turns out I'm working in a Windows environment with Microsoft Expression 2.0 HTML editor. The code needed to be converted to a UNIX environment with dos2unix which is installed in the hoster environment and can be accessed from the shell...Thanks for reading this thread to any who read it.
Related
I have been attempting to run my python script as a service, and have followed the advice contained in several previous forum posts. However, these have not helped me thus far. Here is what I have attempted up until now:
Used an SMWinservice class that allowed me to install my Python script as a service. This solution, however, would not launch. If I would try to start it, I would receive an error message.
I have tried using NSSM with : nssm install myService pathToInterpreter PathToScript. Note, all files etc. can be found in the local directory of the PathToScript. For what its worth, I also tried using the GUI version of NSSM. When I rebooted my computer, it showed as "Paused" in task manager. I stopped it, and then tried to run it again, and I received an error. I have tried NSSM with both python.exe and pythonw.exe.
I suspect that a possible source of error is the fact that my program uses a text file as a configuration file. This configuration file has been coded as being in my local working directory. However, I wouldn't think this would be an issue with NSSM. I know for a fact that my program will completely exit, using the exit command, if the configuration file is not found.
I was thinking of doing a batch file and starting the batch file with the script and running it like that, but I prefer a service since it can monitor the process, can restart it, or windows can notify me via email if there is an issue with my service.
For completeness, I should also mention that the program runs without issue outside of a service. For the reason that the program runs as expected, I decided to not post the code, unless someone would like to see it for whatever reason.
I am trying to create a web application using flask. I have already gotten somewhat comfortable with using python, and have done so using spyder, inside of Anacanda Navigator. Now I am playing around with flask doing basic functions and have successful so far by testing it out in local server 127.0.0.1:5000. The problem I am having is that I cannot stop the server once I run the script in spyder. I have stopped the script and run other scripts through the console, but the local server remains the same.
The reason this is a problem for me is because when I try to change files and run a different flask script, the server does not update with the new information. For example, if I run a flask script that returns "Hello World" on the main page, and then I stop that file, open a new file that has a different flask script that returns "The sky is blue" the server does not change when I check it on chrome or any other browser. It will onyl return "Hello World"
I have been able to fix this problem by completely restarting my computer, but I am wondering if there is another way, just to restart the local server, 127.0.0.1:5000. Thank You!
Also I am using windows
I do : "Run > Configuration per file > Execute in an external system terminal",
then when you run your .py containing the app.run, it will be launched in an external console. If you close the console the server will be closed too.
To Kill the local server, you may use Ctrl+C command and not any other command. This command is also mentioned when the server is up and running.
I've been having this precise issue and have been smashing my head against the wall for a couple of hours. I posted the referenced StackOverflow question (my first actually) and it seems that running a script from inside Spyder is the wrong way to go as it leaves runaway background processes running, even after restarting Spyder.
I got the recommendation to only launch my *.py code from the command prompt. Furthermore I was told to do this:
set FLASK_APP=main1.py then set FLASK_DEBUG=1 then flask run
though I'm not sure what that does, so I will investigate. I was about to restart my computer as a last ditch effort until I looked in my Windows Task Manager and found some Python tasks running. After [end task] them both I was able to launch the updated webpage on my local host.
I have a program on Windows Server 2012 that:
-reads sql query from text file in the same location
-imports helper functions from file in the same location
-executes query on sql server (in the same network) and saves the results
-creates a google spreadsheet from the results (using API credencials that are in the same location)
When I log in to tthe server and execute the file in cmd: python myscript.py everything is fine. However when I try to do the same from Task Scheduler it fails. I get 0x1 error.
This is what I put in my Scheduler actions:
program/script - quoted full path to python.exe (which is in Anaconda folder)
Arguments - quoted full path to myscript.py
Start in - blank
I have tried running it as myself, SYSTEM, Administrators. Also tried Highest priveleges and user logged on or not options... Also followed another solution on SO that recommended running cmd and then "/c python full/path/to/myscript.py" But it's always the same.
It´s very frustrating. I realize it's not strictly coding related issue but I am sure many python programmers had it.
Have you got the same error when starting non-python tasks with scheduler?
If not - I would try to install clear Python and create new schedule .bat file with
powershell C:\Python27\python.exe C:\Python27\file.py
pause
being new with python on a raspberry pi, I downloaded the sample for accessing a google calender given here: https://developers.google.com/api-client-library/python/ and made it run. Just renamed the original file and wrote some code around it. Script works fine when launched from the command line.
But when calling the script hourly via cron, an additional (or new) authentication is required: I'm told to copy a link to the browser, get the 'success code' and copy this into the raw input line the script is intended to show me. The problem is, that this message is sent to my postbox by cron via email and the script is stopped. So I don't have the chance to enter the 'success code' and have it authenticated.
Any ideas about how to allow the cron-activated script reading my calender?
SOLVED!
I added several own log-commands to the scripts in order to trace 'Where am I and what values do my variables have'. After running through the scripts manually via command line and automatically via cron, I compared these logs and found out that when started by cron, several files couldn't be opened. The file names were given without any path, so they were expected to be in the path I called the first script from via commandline. When launched by cron, these files could not be opened, even though I added the relevant paths to PATH= and PYTHONPATH=
So what helped: try using absolute (and full) paths to any files you want to access.
I have a simple CGI python script with an html output:
print "Content-Type: text/html"
print
print hours,minutes,seconds,","
When I run it from my linux shell, it runs fine but when called from the browser, all I get is a blank page. I used to have this problem before when I used CRLF EOF instead of LF but I changed that and it worked fine until some recent modification.
I don't know what to do when the script runs fine from shell but not when called from a browser.
<!-- SHTML Wrapper - 500 Server Error --> means that something is going wrong on the server. The most common cause in CGI scripts for this error is that there is an uncaught error in the CGI script itself, causing it to prematurely terminate. Your best bet is to check your Apache error logs. These will normally be in /var/log/<name of Apache install>/error.log (This could be /var/log/apache2/error.log or /var/log/httpd/error.log, etc.)
Since you've said that this works well in the shell, my guess is that this is an issue with sys.path (remember, Apache is a different user, it will have different settings), but I would need to see more to be certain.
Other issues could be:
Different Python version (3 vs. 2)
File has the wrong permissions (755 is the standard, I believe)
Syntax error somewhere in Python which is environmentally dependant