user2737948
user2737948

Reputation: 339

Python script using webjobs in azure

Hello I'm getting an error when uploading a new azure webjob. The error says it cant create the webjob.

I followed this tutorial which I found it in a question that was asked in here. Link

My script is the following:

import sys, os
sys.path.append(os.path.join(os.getcwd(), "site-packages"))
import requests as req

r = req.get('http://my_website.azurewebsites.net/user/cron')
# Development
# r = req.get('http://localhost:5000/user/cron')
print(r.status_code)

And the structure of my files is this one enter image description here

If anyone can point out where I made a mistake, I just searched for hours and many questions and tutorials point out this is the proper way to add a library in Azure.

Upvotes: 1

Views: 2919

Answers (1)

Jay Gong
Jay Gong

Reputation: 23792

Please refer to the steps as below which I uploaded python script into Webjobs previously.

Step 1 : Use the virtualenv component to create an independent python runtime environment in your system.Please install it first with command pip install virtualenv if you don't have it.

If you installed it successfully ,you could see it in your python/Scripts file.

enter image description here

Step2 : Run the commad to create independent python runtime environment.

enter image description here

Step 3: Then go into the created directory's Scripts folder and activate it (this step is important , don't miss it)

enter image description here

Please don't close this command window and use pip install <your libraryname> to download external libraries in this command window.

enter image description here

Step 4:Keep the Sample.py uniformly compressed into a folder with the libs packages in the Libs/site-packages folder that you rely on.

enter image description here

Step 5: Create webjob in Web app service and upload the zip file,then you could execute your Web Job and check the log

enter image description here

You could also refer to the SO thread :Options for running Python scripts in Azure

Hope it helps you.

Upvotes: 3

Related Questions