[Python] Getting 500 error in python while trying to connect with API using exact same...

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    Hi i have below code written in python where i am trying to connect with Api using the exact same token , payload and headers as postman and send a create request same as i am doing in postman, in postman its working fine but in python its throwing HTTP error occurred:500 server error for url , response content is {timestamp, status:500, error: internal server error}

    Below is my code in python i am not sure what to do in order to make it work i have tried exploring every option and every article on internet and also generated code using postman and modified it but was not successful- below code was generated in postman codegen and i have modified it but still its throwing errror, errors that i am facing i have given above-

    import requests
    import json

    url = "http://localhost:8080/apim/execute/repayments/v3/dummy-acceptance"

    payload = {
    "customer": {
    "id": "cust00001",
    "name": {
    "first_name": "Matthew",
    "last_name": "Peterson"
    },
    "email": "matthew@gmail.com"
    },
    "method": {
    "type": "FPS"
    },
    "transaction": {
    "id": "dummy456721094299",
    "amount": 62.08,
    "currency_code": "GBP",
    "country_code": "GB",
    "url": {
    "accepted": "http://accepted.com",
    "declined": "http://declined.com"
    },
    "reason": "Purchased goods",
    "reference": "ref_0974299",
    "product_info": [
    {
    "id": "prod00007",
    "name": "Apple Laptop",
    "quantity": 1,
    "amount": 62.08,
    "description": "Laptop Purchased"
    }
    ],

    "expiry_time": 1000
    }
    }

    headers = {
    "Idempotency-Id": "12456478591",
    "Content-Type": "application/json",
    "Merchant-Id": "dummyuEFPS2409",
    "Authorization": "Bearer eyJ0eXAiOiJKV1QMFB231pUMg1jHfU2SaDfRj2b_QJoPydIzXfsPlmSEGMzjRUDI",
    "Operation": "AUTHORIZE"
    }

    try:
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    response.raise_for_status() # Raise an exception for HTTP errors
    print("success", response.json())

    except requests.exceptions.HTTPError as errh:
    print("HTTP error occurred:", errh)
    print("Response content:", response.text)
    except requests.exceptions.ConnectionError as errc:
    print("Error Connecting:", errc)
    except requests.exceptions.Timeout as errt:
    print("Timeout Error:", errt)
    except requests.exceptions.RequestException as err:
    print("An error occurred:", err)

    Continue reading...

Compartilhe esta Página