from flask import Flask, jsonify, request
import requests
import json
app = Flask(name)
@app.route(‘/getrates’ , methods=[“POST”])
def get_rates():
data12 = json.loads(request.data)
print("Data12 $$$$$$$$$4 : ",data12)
headers = {
‘Content-Type’: ‘application/json’,
‘API-Key’: ‘’
}
payload = {
"rate_options": {
"carrier_ids": data12['rate_options']['carrier_ids'],
"service_codes": data12['rate_options']['service_codes']
},
"shipment": {
"ship_from": {
"name": "Customer Service",
"company_name": " Warehouse",
"address_line1": " Wolf Rd",
"city_locality": "Lat",
"state_province": "NY",
"postal_code": "12110",
"country_code": "US",
"phone": "212-400-7488"
},
"ship_to": {
"name": data12['shipment']['ship_to']['name'],
"address_line1": data12['shipment']['ship_to']['address_line1'],
"city_locality": data12['shipment']['ship_to']['city_locality'],
"state_province": data12['shipment']['ship_to']['state_province'],
"postal_code": data12['shipment']['ship_to']['postal_code'],
"country_code": data12['shipment']['ship_to']['country_code'],
"address_residential_indicator": data12['shipment']['ship_to']['address_residential_indicator'],
},
"packages": [
{
"weight": {
"value": data12['shipment']['packages'][0]['weight']['value'],
"unit": "pound"
},
"dimensions": {
"length": data12['shipment']['packages'][0]['dimensions']['length'],
"width": data12['shipment']['packages'][0]['dimensions']['width'],
"height": data12['shipment']['packages'][0]['dimensions']['height'],
"unit": "inch"
}
}
]
}
}
endpoint_url = "https://api.shipengine.com/v1/rates"
# custom functions to get employee info
def get_name(data):
return data.get('total_amount')
response = requests.post(endpoint_url, headers=headers, json=payload)
print("Response : ", response)
# Check if the request was successful (status code 200)
# global l_rate_id,l_carrier_id,l_total_amount
service_code = []
if response.status_code == 200:
# Parse the JSON response
data = response.json()
print("Data@@@@@@@@@@@@ : ", data)
print(len(data))
# return "True"
for doc in data['rate_response']['rates']:
if doc['service_code'] == "usps_priority_mail":
if doc["package_type"] == "package":
rate_id = doc['rate_id']
carrier_id = doc['carrier_id']
service_type = doc['service_type']
carrier_nickname = doc['carrier_nickname']
service = doc['service_code']
total_amount = doc['shipping_amount']['amount'] + doc['insurance_amount']['amount'] + doc['confirmation_amount']['amount'] + doc['other_amount']['amount']
doc['total_amount'] = total_amount
service_code.append(doc)
else:
rate_id = doc['rate_id']
carrier_id = doc['carrier_id']
service_type = doc['service_type']
carrier_nickname = doc['carrier_nickname']
service = doc['service_code']
total_amount = doc['shipping_amount']['amount'] + doc['insurance_amount']['amount'] + doc['confirmation_amount']['amount'] + doc['other_amount']['amount']
doc['total_amount'] = total_amount
service_code.append(doc)
print("Service_code : ", service_code)
print(len(service_code))
service_code.sort(key=get_name)
print("Service_code : ", service_code[0])
else:
pass
# Create a JSON response with the desired variables
return jsonify(service_code)
this is flask code and i want to sent the custom response, I am getting this error in postman ($.respond() not called for this invocation) . Please help me to resolve this error.