Saad Qureshi
Saad Qureshi

Reputation: 738

How to 'pip install packages' inside Azure WebJob to resolve package compatibility issues

I am deploying a WebJob inside Azure Web App that uses Google Maps API and Azure SQL Storage.

I am following the typical approach where I make a WebJob directory and copy my 'site-packages' folder inside the root folder of the WebJob. Then I also add my code folder inside 'site-packages' and make a run.py file inside the root that looks like this:

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

import aero2.AzureRoutine as aero2

aero2.run()

Now the code runs correctly in Azure. But I am seeing warnings after a few commands which slow down my code.

Error I have tried copying 'pyopenSSL' and 'requests' module into my site-packages folder, but the error persists.

However, the code runs perfectly on my local machine.

How can I find this 'pyopenSSL' or 'requests' that is compatible with the python running on Azure?

Or

How can I modify my code so that it pip installs the relevant packages for the python running on Azure?

Or more importantly,

How can I resolve this error?

Upvotes: 0

Views: 2163

Answers (3)

alys
alys

Reputation: 331

I followed this article and kind of 'pip installed' the pymongo library for my script. Not sure if it works for you but here are the steps:

  1. Make sure you include the library name and version in the requirements.txt
  2. Deploy the web app using Git. The directory should include at least requirements.txt (only to install whatever is in requirements.txt in the virtual environment, which is shared with Web App in D:\home\site\wwwroot\env\Lib\site-packages)
  3. add this block of code to the Python code you want to use in the WebJob zip file.

import sys

sitepackage = "D:\home\site\wwwroot\env\Lib\site-packages"

sys.path.append(sitepackage)

Upvotes: 0

Will Shao - MSFT
Will Shao - MSFT

Reputation: 1207

@Saad, If your webjob worked fine on Azure Web App, but you got inscuritywaring, I suggest you can try to disable the warning information via this configuration(https://urllib3.readthedocs.org/en/latest/security.html#disabling-warnings ). Meanwhile,requests lib has some different with the high version, I recommend you refer to this document: http://fossies.org/diffs/requests/2.5.3_vs_2.6.0/requests/packages/urllib3/util/ssl_.py-diff.html And Azure web app used the Python 2.7.8 version which is lower than 2.7.9. So you can download the requests lib as version 2.5.3

enter image description here

Upvotes: 1

Gary Liu
Gary Liu

Reputation: 13918

According the doc referred in the warning message https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning:

Certain Python platforms (specifically, versions of Python earlier than 2.7.9) have restrictions in their ssl module that limit the configuration that urllib3 can apply. In particular, this can cause HTTPS requests that would succeed on more featureful platforms to fail, and can cause certain security features to be unavailable.

So the easiest way fix this warning, is to upgrade the python version of the Azure Web Apps. Login the Azure manager portal, change the python version to 3.4 in Application settings column: enter image description here

As I test in webjob task to use requests module to request a "https://" url, and since upgrade python version to 3.4, there are no more warnings.

Upvotes: 0

Related Questions