Azure function "Test/Run" functionality on portal returning internal server error for returning valid func.HttpResponse.

Vishwas Patel 1 Reputation point

I created a simple Azure function with Http Trigger(python) which have following code:

   def main(req: func.HttpRequest) -> func.HttpResponse:'Python HTTP trigger function processed a request.')  
       return func.HttpResponse(str(12345))  

It returns 12345 in get request through browser and postman, but portal raises 500 error when testing using it's Test/Run Functionality.

At same time if I have something like a123 instead of 12345, it works fine. Any idea why this occurs?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
2,598 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rohit Anand 6 Reputation points

    The same issue is faced by me,
    And I've noticed even after having error in Azure portal, The same code executes fine in other environments like VS Code, or postman website,
    and even it gives expected result after implementing it in ADF pipeline.

    This could be backend issue of Azure or may be something else, but somehow the code function in required manner and gives us the expected output.

    The HttpResponse() require string as a return output and may be it faces some issue during the conversion of integer to string.

    No comments

  2. MayankBargali-MSFT 49,701 Reputation points Microsoft Employee

    @Vishwas Patel Thanks for reaching out. I will also suggest you to review Azure Functions diagnostics to find the root cause of the 500 error. It will give you more details on the exception/stack trace which is resulting in 500 error. It will also provide insights to resolve the issue. Alternative you can also review your application insights logs for your function to know more about the full exception trace/error message that is causing 500 error.

    Looking into your code that you have shared I don't see any issue or the function executing depends on your input value. Can you please confirm if you have specified package in your requirements.txt? The more details on the error can be found using Azure Functions diagnostics or looking into application insights logs.