'Azure functions : Failure Exception: Error: unsupported locale setting Stack

At some point in my code I set the locale :

    import locale
    locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")

When I run this code in azure-functions I get the following error :

Result: Failure Exception: Error: unsupported locale setting

How can I configure the azure function to support the locale I want to use?



Solution 1:[1]

I believe locale module is OS dependent, So I have tried to make the Azure Functions (Python) work with the below code:

import  logging
import  azure.functions  as  func
import  locale
import  platform  
  

def  main(req: func.HttpRequest) -> func.HttpResponse:

logging.info('Python HTTP trigger function processed a request.')
my_os = platform.system()  

if  my_os == 'linux':
    locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
    logging.info(my_os)

# else:
# locale.setlocale(locale.LC_ALL, "fr_FR")
# logging.info(my_os)

return  func.HttpResponse(f"Hello {locale.getlocale(locale.LC_ALL)} and {my_os}. This HTTP triggered function executed successfully.")

Requirements.txt:

azure-functions
locales

enter image description here

When we deploy the Azure Function Python using VS Code, it will deploy to Linux OS. Getting the OS Value and then setting the locale worked when running the Azure Python Function to Azure.

enter image description here

In the above code, Else block works if the Azure Function Python is deployed to Windows Container in Azure and also in Local Windows Operating System.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HariKrishnaRajoli-MT