I am on Windows 7 and am trying to automate some email-related list updates. I have a python script that pulls-in emails, downloads certain attachments and sends me back a new email with some results. This all works great when I run the code manually:
via Windows command prompt.
Within my IDE.
Wrapping it in a .bat file and dbl-clicking the bat file.
To be clear here:
When executed in any of the above ways, the script successfully checks emails, parses the attachments and sends an email to myself containing the desired information.
Problem: When I try to set-up a scheduled task (I have admin privileges) on my local PC to run the .bat file, the script terminates at the following lines:
outlook_app = win32com.client.Dispatch("Outlook.Application")
outlook = outlook_app.GetNamespace("MAPI")
Have tried both running as a .bat and also by setting the python path as the program/script and adding the arguments and start in. Worked perfectly for months and all the sudden stopped. Other python scripts without the win32com library run just fine.
Related
i am new to the community and new in using servers and could use some help.
I am trying to setup an automatic JSON parser to another server using http post calls. The idea is as follows:
I manually put JSON files into a folder Input on the server
A python script that is always running on the server reads the files located within the folder
It reads the JSON files, posts all objects to another server, and moves the files to a "Processed" folder one file at a time.
I have been given a Windows Server, with Windows Server Manager 2016, and have managed to do the following:
installed python 3.8.2. on the windows server
able to run a python script using powershell
Installed NSSM to create a windows service
Now the windows server manager says i cannot resume or start the service that i tried to install via NSSM.
I am very new to servers, as well as python itself. Can somebody help me to get a python script running 24/7 on a windows server with windows server manager 2016?
Edit:
I managed to create a python script that can read files, upload them and move them to a processed folder, but i still have to run it by myself while i want it to always run on the server
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 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
I have stabled password less login between two ubuntu system then I run following command
$scp file user#hostname2:/tmp/
it works fine and I got file transferred without asking for password.
however when I try to execute the same through following python statement-
subprocess.check_output(['scp', file, r'user#hostname2:/tmp/'])
I am not able to copy files to remote computer, so I am bit curious about which user's privileges python program uses to execute command via subprocess ?
How can I debug such programs ?
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.