I wanted to know how could I send a curl HTTP Post and store the value of a specific parameter of its curl HTTP response using Python.
So, I first need to execute this HTTP POST in Python which I imagine I will do with the Requests library (correct me if I should better to use another):
curl -X POST \
'https://api.mercadopago.com/checkout/preferences' \
-H 'content-type:application/json' \
-H 'Authorization: Bearer TEST-6716665210379951-021722-28e8be02433284aa5f78fcc451ba3fec-208040995' \
-d '{
"items": [
{
"title": "Dummy Item",
"description": "Multicolor Item",
"quantity": 1,
"currency_id": "ARS",
"unit_price": 10.0
}
]
}'
When I run that curl POST, I get this HTTP response:
{"additional_info":"","auto_return":"","back_urls":{"failure":"","pending":"","success":""},"binary_mode":false,"client_id":"6716665210379951","collector_id":208040995,"coupon_code":null,"coupon_labels":null,"date_created":"2020-11-12T01:08:13.385+00:00","date_of_expiration":null,"expiration_date_from":null,"expiration_date_to":null,"expires":false,"external_reference":"","id":"208040995-2b4ed779-4a0c-4730-8811-1bb194164d1f","init_point":"https://www.mercadopago.com.ar/checkout/v1/redirect?pref_id=208040995-2b4ed779-4a0c-4730-8811-1bb194164d1f","internal_metadata":null,"items":[{"id":"","category_id":"","currency_id":"ARS","description":"Multicolor Item","title":"Dummy Item","quantity":1,"unit_price":10}],"marketplace":"NONE","marketplace_fee":0,"metadata":{},"notification_url":null,"operation_type":"regular_payment","payer":{"phone":{"area_code":"","number":""},"address":{"zip_code":"","street_name":"","street_number":null},"email":"","identification":{"number":"","type":""},"name":"","surname":"","date_created":null,"last_purchase":null},"payment_methods":{"default_card_id":null,"default_payment_method_id":null,"excluded_payment_methods":[{"id":""}],"excluded_payment_types":[{"id":""}],"installments":null,"default_installments":null},"processing_modes":null,"product_id":null,"redirect_urls":{"failure":"","pending":"","success":""},
"sandbox_init_point":"https://sandbox.mercadopago.com.ar/checkout/v1/redirect?pref_id=208040995-2b4ed779-4a0c-4730-8811-1bb194164d1f","site_id":"MLA","shipments":{"default_shipping_method":null,"receiver_address":{"zip_code":"","street_name":"","street_number":null,"floor":"","apartment":"","city_name":null,"state_name":null,"country_name":null}},"total_amount":null,"last_updated":null}
And I would like to store as a variable, in Python, the specific value of the response parameter "sandbox_init_point" which in this case has a value of "https://sandbox.mercadopago.com.ar/checkout/v1/redirect?pref_id=208040995-2b4ed779-4a0c-4730-8811-1bb194164d1f"
In summary, I would like to know how to execute in Python an HTTP request (curl POST) and store the specific value of a parameter of the corresponding HTTP response.
Thank you so much in advance to you everyone for making coding a lot easier!