Object of type function is not JSON serializable in Django

I have been trying to pass this data in json format but i keep getting this error. I am getting all the data and passing it to a payment getaway for processing. But anytime I pass the data i get the error message

    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable
def paytes(request): 
    amount = 10
    desc = "USSD"
    category = 'Robert'
    phone = "233244491909"
    vote = "10"
    slug = "test"
    award = "test"
    url = 'https://api.pays.co/charge'
    transaction_id = random.randint(100000000000, 999999999999)
    data = json.dumps({
        "reference": transaction_id,
        "amount": amount,
        "phone": phone,
        "email":"customer@gmail.com",
        "mobile_money": {
        "phone" : "0244496709",
        "provider" : "MTN"
         },
        "label" : desc,
        "metadata":{
            "custom_fields": [
                {
                    "value": desc,
                    "nominee_name": slug,
                    "transaction_id": transaction_id,
                    "amount": amount,
                    "award": award,
                    "category": category,
                    "email": email,
                    "phone": phone,
                    "vote": vote,
                }
            ]
        } 
})
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer texk_002929992',
        'Cache-Control': 'no-cache'
    }
    response = requests.post(url, data=data, headers=headers)
    return HttpResponse(response)

Tried dumping your data and it gave me the error "name email is not defined". Changing it to some string solves the issue. So most probably it is an auto import or something else.

Email is not defined

amount = 10
desc = "USSD"
category = 'Robert'
phone = "233244491909"
vote = "10"
slug = "test"
award = "test"
url = 'https://api.pays.co/charge'

"email": email,

Back to Top