title: Azure Function: 500 internal internal server error in Run/Test Mode
body: <p>I want to Test my azure function using the Azure Apps feature to Run/Test mode but it is throwing the '500 internal server error'.
  I am able to debug the same code in my local environment but when to trigger the same code on the azure portal then it is getting failed without any proper error logs.
  <a href="https://i.stack.imgur.com/yATm8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yATm8.png" alt="enter image description here" /></a>
  This Azure function will read the json format data from the event hub and write the same to the blob storage. I am using python for the azure function development.
  Here is the code:
  <em><strong>init</strong></em>.py</p>
  <pre><code>from typing import List
  import logging
  import os
  import azure.functions as func
  from azure.storage.blob import BlobClient
  import datetime
  import json
  
  storage_connection_string = os.getenv('storage_connection_string_FromKeyVault')
  
  container_name = os.getenv('storage_container_name_FromKeyVault')
  
  today = datetime.datetime.today()
  
  
  def main(events: List[func.EventHubEvent]):
      for event in events:
          a = event.get_body().decode('utf-8')
          json.loads(a)
          logging.info('Python EventHub trigger processed an event: %s', a)
          logging.info(f'  SequenceNumber = {event.sequence_number}')
          logging.info(f'  Offset = {event.offset}')
  
          blob_client =  BlobClient.from_connection_string(storage_connection_string, container_name, str(today.year) +&quot;/&quot; + str(today.month) + &quot;/&quot; + str(today.day) + &quot;/&quot; + str(event.sequence_number) + &quot;.json&quot;)
  
          blob_client.upload_blob(event.get_body().decode(),blob_type=&quot;AppendBlob&quot;)
  </code></pre>
  <p><strong>local.settings.json</strong></p>
  <pre><code>{
    &quot;IsEncrypted&quot;: false,
    &quot;Values&quot;: {
      &quot;AzureWebJobsStorage&quot;: &quot;&lt;Endpoint1&gt;&quot;,
      &quot;FUNCTIONS_WORKER_RUNTIME&quot;: &quot;python&quot;,
      &quot;storage_connection_string_FromKeyVault&quot;: &quot;&lt;connectionString&quot;,
      &quot;storage_container_name_FromKeyVault&quot;: &quot;&lt;container_name&gt;&quot;,
      &quot;EventHubReceiverPolicy_FromKeyVault&quot;: &quot;&lt;Endpoint2&gt;&quot;
    }
  }
  </code></pre>
  <p><strong>function.json</strong></p>
  <pre><code>{
    &quot;scriptFile&quot;: &quot;__init__.py&quot;,
    &quot;bindings&quot;: [
      {
        &quot;type&quot;: &quot;eventHubTrigger&quot;,
        &quot;name&quot;: &quot;events&quot;,
        &quot;direction&quot;: &quot;in&quot;,
        &quot;eventHubName&quot;: &quot;pwo-events&quot;,
        &quot;connection&quot;: &quot;EventHubReceiverPolicy_FromKeyVault&quot;,
        &quot;cardinality&quot;: &quot;many&quot;,
        &quot;consumerGroup&quot;: &quot;$Default&quot;,
        &quot;dataType&quot;: &quot;binary&quot;
      }
    ]
  }
  </code></pre>
  <p><strong>Please note that this error is throwing when I am clicking on Run/Test on the portal. but the same code is also running fine after deployment.</strong></p>