I want to write a file to my Azure DataLake Gen2 with an Azure Function and Python.
Unfortunately I'm having the following authentication issue:
Exception: ClientAuthenticationError: (InvalidAuthenticationInfo) Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
'WWW-Authenticate': 'REDACTED'
Both my account and the Function app should have the necessary roles for accessing my DataLake assigned.
And here is my function:
import datetime
import logging
from azure.identity import DefaultAzureCredential
from azure.storage.filedatalake import DataLakeServiceClient
import azure.functions as func
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
credential = DefaultAzureCredential()
service_client = DataLakeServiceClient(account_url="https://<datalake_name>.dfs.core.windows.net", credential=credential)
file_system_client = service_client.get_file_system_client(file_system="temp")
directory_client = file_system_client.get_directory_client("test")
file_client = directory_client.create_file("uploaded-file.txt")
file_contents = 'some data'
file_client.append_data(data=file_contents, offset=0, length=len(file_contents))
file_client.flush_data(len(file_contents))
logging.info('Python timer trigger function ran at %s', utc_timestamp)
What am I missing?
THX & BR
Peter