Hello @K M Rahaman - Sorry to hear that you're encountering this issue. Based on the details you have posted, the error 500 is quite generic and it'd be difficult to diagnose the root cause. Have you looked at & gone through the Function logs? Feel free to open a support case for a support engineer who has a deeper insight into your environment to take a closer look. Alternatively, (in case your subscription doesn't carry a support plan) you can send us an email at azcommunity at microsoft dotcom
(with your subscription ID and function app name included) and we'd be happy help as well.
Internal Server error 500 Azure Functions App
I have tried deploying my HTTP Trigger function to Azure Functions with runtime version 3.8 on linux serverless consumption plan. My function works fine on local machine using visual studio code but fails on azure after deploying, showing a runtime exception. I also tried to deploy an app service plan to edit and deploy function code on azure portal itself but the app service plan fails to deploy showing unexpected internal server error 500. Actually I am trying to deploy this function for a competition I am participating and the deadline's tomorrow. Urgent help will be appreciated.
Here is my program:
import logging
import azure.functions as func
from datetime import datetime,date,timezone
import threading
from time import sleep
import uuid
import firebase_admin
from firebase_admin import credentials,firestore
import google.cloud
from google.cloud import firestore as fire
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
objectId = req.params.get('objectId')
if not objectId:
try:
req_body = req.get_json()
except ValueError:
pass
else:
objectId = req_body.get('objectId')
if objectId:
uuidDate=Attendance().update_create_if_missing(objectId)
return func.HttpResponse(f"{uuidDate}",status_code=200)
else:
return func.HttpResponse(
"Please pass a objectId on the query string or in the request body",
status_code=400
)
class Attendance(object):
if not firebase_admin._apps:
cred = credentials.Certificate(r"HttpTrigger1\serviceAccountKey.json")
default_app = firebase_admin.initialize_app(cred)
db = firestore.client()
def getUuidDate(self):
datetime1=datetime.now(timezone.utc)
min_slot=str((datetime1.hour*60+datetime1.minute)//10)
Date=datetime1.isoformat()[:10]+'0'*(3-len(min_slot))+min_slot
uuid1=str(uuid.uuid4())
uuid1=uuid1[:9]+'0786'+uuid1[13:]
return uuid1+Date
def update_create_if_missing(self,objectId):
# [START update_create_if_missing]
user_ref = Attendance.db.collection(u'users').document(f"{objectId}")
uuidDate=self.getUuidDate()
doc = user_ref.get()
if doc.exists:
if self.check(doc):
user_ref.update({u'contacts_temp': fire.ArrayUnion([f"{uuidDate}"])})
else:
user_ref.set({u'contacts_temp': fire.ArrayUnion([f"{uuidDate}"])},merge=True)
else:
# Atomically add a new region to the 'regions' array field.
user_ref.set({u'contacts_temp': fire.ArrayUnion([f"{uuidDate}"])},merge=True)
return uuidDate
# [END update_create_if_missing]
def check(self,doc):
# [START_EXCLUDE]
try:
doc.get(u'contacts_temp')
return True
except:
return False
# [END_EXCLUDE]
These are my requirements
azure-functions
firebase-admin
google-cloud-firestore
google-api-core==1.17.0
google-cloud-core==1.3.0
1 answer
Sort by: Most helpful
-
Mike Urnun 9,811 Reputation points Microsoft Employee
2020-08-14T02:56:32.85+00:00