Not able to capture error for Python app

Hello Everyone,

I am not able to capture error message in APM for python app.Below is the code .

import requests
import elasticapm
from elasticapm import Client
from elasticapm.instrumentation.control import instrument
import logging
es_url="https://my-deployment-60149c.es.xxxxx.com"
es_auth=('elastic','pass')

# Configure the APM client
client = Client({
    'SERVICE_NAME': 'app',
    'SERVER_URL': 'https://my-deployment-60149c.xxxx.elastic-cloud.com',  # Replace with your APM Server URL
    'SECRET_TOKEN': 'token',  # Optional, if your APM server requires it
    'ENVIRONMENT': 'production'
})
instrument()  # Enables automatic instrumentation for supported libraries
def connection(es_url,es_auth):
    client.begin_transaction(transaction_type="get")
    response=requests.get(es_url,auth=es_auth,verify=False)
    client.end_transaction(name="get_connection" ,result="success")
    #return response.status_code

def create_index(es_url,es_auth,index_name):
    client.begin_transaction(transaction_type="put")
    json_data={
        "settings": {
            "number_of_shards": 1,
            "number_of_replicas": 0
        },
        "mappings": {
            "properties": {
                "emp_name": {"type": "text"},
                "emp_code": {"type": "integer"},
                "department": {"type": "keyword"}
            }
        }
    }
    try:
        response=requests.put(f'{es_url}/{index_name}',auth=es_auth,json=json_data)
        client.end_transaction(name="put_index" ,result="success")
        logging.info(f'Index {index_name} created successfully.')
        
    except requests.exceptions.HTTPError as err:
                           elasticapm.capture_exception(err,handled=True)  # Captures the full stack trace and error

   
#connection(es_url,es_auth)
#print(stage1)
create_index(es_url,es_auth,'employee')
#print(stage2)

I am getting failure but not the reason .