简体   繁体   English

尝试发送数据时 POST API python 出错

[英]Error in POST API python while trying to send data

Here is the json data to send这是要发送的 json 数据

{
  "mobile": "1234567890"
}

Here is the python code:这是 python 代码:

from urllib import response
import requests
import urllib 
import json 

query = {"mobile": "1234567890"}
headers =  {"Content-Type":"application/json"}
url = 'https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP'
y = requests.post(url, data=query, headers=headers)

print(y)

Response from the API:来自 API 的响应:

c:/pythonprojects/covid-otp-requests.py
<Response [400]>

I am a newbie, I don't understand the mistake I am making, Can someone please help me out?.我是新手,我不明白我所犯的错误,有人可以帮助我吗?

Fix here:在这里修复:

from urllib import response
import requests
import urllib 
import json 

params = {
    "mobile": "1234567890"
}
headers =  {"Content-Type":"application/json"}
response = requests.post("https://cdn-api.co-vin.in/api/v2/auth/public/generateOTP", data=json.dumps(params))
print(response)

details = response.json()

print(details)

The parameters has to be sent in json format which I making a mistake in.参数必须以我弄错的 json 格式发送。

Thank you all!谢谢你们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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