简体   繁体   中英

How to make a API call using requests in Python

I'm a newbie in python and I'm dealing with this problem, I want to make an API POST request by using Python but I can't send a request with this. Can anyone help me figure it out? This is what I have:

import requests

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
data = 
{
    "token": "TokenStaging",
    "OrderCode": "23FNQY46"
}
r = requests.post('https://dev-online-gateway.ghn.vn/apiv3-api/api/v1/apiv3/OrderInfo',
    headers=headers, data=data)

API document link: https://api.ghn.vn/home/docs/detail?id=29#parameter-examples-APIV3-OrderInfo-1_0_0-0

After some research and testing, i finally can call that API with this:

import requests

r = requests.post('https://console.ghn.vn/api/v1/apiv3/OrderInfo',
 json={
  "token": "TokenStaging",
  "OrderCode": "23FNQY46"
})

Thank you guys for all your support

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM