Can anyone help me with the following error:
Result: Failure Exception: ImportError: cannot import name 'EventGridPublisherClient' from 'azure.eventgrid'
This is the code for the HTTPTrigger:
import os
import logging
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# Parse request body
#req_body = req.get_json()
# Get Event Grid topic endpoint and key from environment variables
topic_endpoint = os.environ.get('EVENT_GRID_TOPIC_ENDPOINT')
topic_key = os.environ.get('EVENT_GRID_TOPIC_KEY')
# Create Event Grid publisher client
credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(topic_endpoint, credential)
# Create an event
event = EventGridEvent(
event_type="MyCustomEventType",
subject="MyCustomSubject",
data={
"message": "Hello, Event Grid!"
},
data_version="1.0"
)
# Publish the event
client.send(event)
# Return a response
return func.HttpResponse("Event published to Event Grid topic.", status_code=200)
The requirements.txt looks like this:
urllib3
uplink
requests
azure-functions
azure
azure-eventgrid
azure-core
Running locally works fine but when I deploy to Azure I get the error above. I'm going in circles and don't seem to find any useful information to help with this. Anyone has an idea?