0

My problem is: I try to execute a fresh uploaded python function in an Azure Function App service and launch it (no matter if I use blob trigger or http trigger) I allways get the same error:

Exception while executing function: Functions.TestBlobTrigger Result: Failure
Exception: TypeError: expected str, bytes or os.PathLike object, not PosixPath
Stack:   File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 284, in _handle__function_load_request
    func = loader.load_function(
  File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call
    return func(*args, **kwargs)
  File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 53, in load_function
    register_function_dir(dir_path.parent)
  File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 26, in register_function_dir
    _submodule_dirs.append(fspath(path))

Why is this happening: when the function is successfully deployed I upload a file in a blob in order to trigger the function but I get allways the same error, caused by the pathlib library (https://pypi.org/project/pathlib/). I have written a very easy function that works in my local vscode and it just prints a message.

import logging
import configparser
import azure.functions as func
from azure.storage.blob import BlockBlobService
import os
import datetime
import io
import json
import calendar
import aanalytics2 as api2
import time
import pandas as pd
import csv
from io import StringIO

def main(myblob: func.InputStream):

    logging.info("BLob Trigger function Launched  ");
    blob_bytes = myblob.read();
    blobmessage=blob_bytes.decode()
    func1 = PythonAPP.callMain();
    func1.main(blobmessage); 

The Pythonapp class is:

class PythonAPP:

    def __init__(self):
        
        logging.info('START extractor. ');
        self.parameter="product";


    def main(self,message1):
        var1="--";
        try:
            var1="---";
            
            
            logging.info('END: ->paramet '+str(message1));
            


        except Exception as inst:
            
            logging.error("Error  PythonAPP.main : " + str(inst));
        return var1;    

My requirements.txt file is:

azure-storage-blob== 0.37.1
azure-functions-durable
azure-functions
pandas
xlrd
pysftp
openpyxl
configparser
PyJWT==1.7.1
pathlib
dicttoxml
requests
aanalytics2

I've created this simple function in order to check if I can upload the simpliest example in Azure Functions, is there any dependencies that am I forgetting?

Checking the status of the functions I found this: enter image description here

------------UPDATE1--------------------

The function is failing because the pathlib import, this is because in the requirements of the function it downloads this library and fails with AZ functions. Please see the requirements.txt file in the following link: https://github.com/pitchmuc/adobe_analytics_api_2.0/blob/master/requirements.txt

Can I exlude it somehow?

Well I can't provide an answer for that, I made a walkarround. In this case I created a copy of the library in a github repository. In this copy I erased the references to the pathlib in the requrements.txt and setup.py because this libary causes the failure in the AZ function APPS. By the way in the requirements file of the proyect make a reference to the project, so please mind the requiremnts file that I wrote above and change aanalytics2 reference to:

git+git://github.com/theURLtotherepository.git@master#egg=theproyectname 

LINKS.

I've checked a lot of examples in google but none of them helped me:

Azure function failing after successfull deployment with OSError: [Errno 107]

https://github.com/Azure/azure-functions-host/issues/6835

https://learn.microsoft.com/en-us/answers/questions/39865/azure-functions-python-httptrigger-with-multiple-s.html

https://learn.microsoft.com/en-us/answers/questions/147627/azure-functions-modulenotfounderror-for-python-scr.html

Missing Dependencies on Python Azure Function --> no bundler flag or –build remote

https://github.com/OpenMined/PySyft/issues/3400

MrPotatoServer
  • 175
  • 5
  • 15

1 Answers1

0

This is a bug in the azure codebase itself; specifically within: azure-functions-python-worker/azure_functions_worker/dispatcher.py

the problematic code within dispatcher looks to be setting up the exposed functions with the metadata parameters found within function.json

you will not encounter the issue if you're not using pathlib within your function app / web app code

if pathlib is available the issue manifests

rather than the simple os.path strings pathlib.Path objects are exposed - deeper down in the codebase there looks to be a conditional import and use of pathlib

to resolve simply remove the pathlib from your requirements.txt and redeploy

you'll need to refactor any of your own code that used pathlib - use equivalent methods in the os module

there looks to have been a ticket opened to resolve this around the time of the OP post - but it is notresolved in the current release

shunte88
  • 21
  • 4