Skip to content Skip to sidebar Skip to footer

Running Python Script From Azure Webjob

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://.scm.azurewebsites.net an

Solution 1:

I tried to realize your needs with Python in WebJob and successfully make it works.

Here is my steps and sample code. My local environment is Python 3.7 on Windows 10.

  1. Create a Python virtual environment and install python-telegram-bot package via commands as below.

    $ mkdir telegram-webjob$ virtualenv telegram-webjob$ cd telegram-webjob$ Scripts\active$ pip install python-telegram-bot$ pip freeze

    enter image description here

  2. I changed your code as my sample code, then run it works fine on local, as below.

    import telegram
    from datetime import datetime as dt
    
    my_token = '<my token>'
    bot = telegram.Bot(token = my_token)
    
    chat_id = '<chat id>'
    message = f"Hello at {dt.now()}"
    bot.sendMessage(chat_id=chat_id, text=message)
    

    enter image description here

    enter image description here

  3. I created a new directoy named webjob and copy my trading.py file and all directories with their files into it, as below.

    enter image description here

  4. Write the startup bat script named run.bat, the code as below.

    D:\home\python364x86\python.exe trading.py

    The D:\home\python364x86\python.exe path is the python364x86 site extension installed path as the figure below.

    enter image description here

  5. Then, I packaged the all directories and files in the webjob directory as a zip file, as below.

    enter image description here

  6. I uploaded it to Azure WebApp as a webjob, as the figure below, and start it.

    enter image description here

    enter image description here

Finally, it works fine for me and I can see the message interval 10 sec displayed in my telegram client.

enter image description here

Post a Comment for "Running Python Script From Azure Webjob"