0

I have an azure function that depends on extras of a specific library, however it seems that Functions is ignoring the extras specified in the requirements.txt

I have specified this in the requirements.txt:

functown>=2.0.0
functown[jwt]>=2.0.0

This should install additional dependencies (python-jose in this case), however it seems like the extras are ignored by Azure functions:

 No module named 'jose'. Please check the requirements.txt file for the missing module. 

I also tested this locally and can confirm that for a regular pip install -r requirements.txt the extras are picked up and python-jose is indeed installed (which I can verify by import jose).

Are there special settings to be set in Azure Function or is this a bug?

Update 1:

In particular I want to install the dependencies on an extra of a python library (defined here and reqs here), which works perfectly when setting up a local environment on my system. So I assume it is not a python or requirements problem. However, it does not work when deploying to Azure Functions, leading me to assume that there is an inherent problem with Azure Functions picking up extras requirements?

felixnext
  • 13
  • 3

1 Answers1

0

I have reproduced from my end and got below results.

Test Case 1:

With the functown Python Package, I have tested in Azure Functions Python Version 3.9 Http Trigger with the below Code:

init.py:

import  logging
from  logging  import  Logger
from  functown  import  ErrorHandler
import  azure.functions  as  func

@ErrorHandler(debug=True, enable_logger=True)
def  main(req: func.HttpRequest, logger: Logger, **kwargs) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

a = 3
b= 5
if  a > b:
raise  ValueError("something went wrong")
else:
print ("a is less than b")

return  func.HttpResponse("Hello Pravallika, This HTTP triggered function executed successfully.", status_code=200)

requirements.txt:

azure-functions
functown

enter image description here

Test Case 2:

This is with the Python-Jose and Jose Libraries in Azure Functions Python v3.9 Http Trigger:

enter image description here

init.py:

import  logging
from  logging  import  Logger
from  functown  import  ErrorHandler
import  azure.functions  as  func
from  jose  import  jwt

@ErrorHandler(debug=True, enable_logger=True)
def  main(req: func.HttpRequest, logger: Logger, **kwargs) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

# Sample Code Test with functown Packages in Azure Functions Python Http Trigger
a = 3
b= 5
if  a > b:
raise  ValueError("something went wrong")
else:
print ("a is less than b")

# Sample Code Test with Jose, Python-Jose Packages in Azure Functions Python Http Trigger
token = jwt.encode({'key': 'value'}, 'secret', algorithm='HS256')
u'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ2YWx1ZSJ9.FG-8UppwHaFp1LgRYQQeS6EDQF7_6-bMFegNucHjmWg'
print(token)

jwt.decode(token, 'secret', algorithms=['HS256'])
{u'key': u'value'}
print(token)

return  func.HttpResponse("Hello Pravallika, This HTTP triggered function executed successfully.", status_code=200)

requirements.txt:

azure-functions
functown
jose
Python-jose

Code Samples taken from the references doc1 and doc1.

For your error, I suggest you:

  1. check the code how you imported the modules such as Jose, functown in the code as I seen similar issue in the SO #61061435 where users given code snippet for how to import the Jose Packages and the above code snippets I have provided in practical.
  2. Make sure you have Virtual Environment installed in your Azure Functions Python Project for running the Python Functions.
Pravallika KV
  • 2,415
  • 2
  • 2
  • 7
  • Not sure I understand the solution here. I can confirm that it will work as intended when I put python-jose in the requirements.txt. However, that is not what I want to do. Rather I want to install the extras of the library (as it is more dynamic) by putting `functown[jwt]` in my requriements.txt. This works fine in local environment but it seems that Azure Functions have a problem with that! (Also added that info as update ot the main question) – felixnext Feb 03 '23 at 09:29