I'm trying to run python script from Azure webjob. This is what I've done following this link
- Access the kudu tool via the url
https://<webapp name>.scm.azurewebsites.net
and installed Python 364x86
via Site Extensions tab
- Confirmed
Python 364x86
is installed in the following path: D:homepython364x86
- Added my script
trading.py
in D:homepython364x86
- Created
run.bat
file with this line of code D:homepython364x86python.exe trading.py
- Included
run.bat
and trading.py
in the webjob zip file
- Deployed, but getting error
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Initializing
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Run script 'run.bat' with script host - 'WindowsScriptHost'
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Running
[09/07/2019 07:02:00 > 0dd02c: ERR ] The filename, directory name, or volume label syntax is incorrect.
[09/07/2019 07:02:00 > 0dd02c: INFO]
[09/07/2019 07:02:00 > 0dd02c: INFO] D:localTempjobsriggeredz2az54ret.wh4>D:homepython364x86python.exe trading.py
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Failed
[09/07/2019 07:02:00 > 0dd02c: SYS ERR ] Job failed due to exit code 1
Functions.cs
public void StartTheBot()
{
// Local
//var fileName = @"C:Users
obertAppDataLocalProgramsPythonPython37-32python.exe";
//var script = @"C:python-scriptsrading.py";
// Production
var fileName = @"D:homepython364x86python.exe";
var script = @"D:homepython364x86rading.py";
var errors = "";
var results = "";
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = fileName,
Arguments = script,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
using (Process process = Process.Start(psi))
{
errors = process.StandardError.ReadToEnd();
results = process.StandardOutput.ReadToEnd();
}
Console.WriteLine("Errors:");
Console.WriteLine(errors);
Console.WriteLine();
Console.WriteLine("Results:");
Console.WriteLine(results);
}
Above code executes python script. It works locally, but once I deploy it to production it fails. Tried so many times, spent plethora of hours, but still unsure why prod doesn't work. Help is appreciated.
trading.py
import telegram
my_token = 'mytoken'
bot = telegram.Bot(token = my_token)
chat_id = 'mychatid'
message = 'Hello
bot.sendMessage(chat_id=chat_id, text=message)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…