RESTAPI Python请求:响应[400]

2024-06-01 02:38:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个python脚本,它允许我将客户机存储和更新到数据库中。这是我试图存储和更新客户端的代码

data = {"first_name": "Client 1", 
        "last_name": "Last1", 
        "address": "12 Street", 
        "phone_number": "9876543210", 
        "email": "client_1@test.com", 
        "password": "testtest", 
        "vehicles": [], 
        "deleted": False}

response = session.post('http://localhost:3000/api/client/register', json = data, verify = False )

data = {"_id": "602b5dbf4b610a0012fbd5e8",
        "first_name": "Client 1",
        "last_name": "Last1",
        "address": "10 Street",
        "phone_number": "9876543210",
        "email": "client_1@test.com",
        "password": "testtest",
        "vehicles": [],
        "deleted": False}

response = session.put('http://localhost:3000/api/client', json = data, verify = False)

print(response)

http://localhost:3000/api/client/register是客户端注册的位置http://localhost:3000/api/client是我们可以看到所有客户机数据库的地方。每次我试图更新客户机的数据时,我总是得到<Response [400]>。我知道这意味着参数输入不正确,但我不知道在哪里。能帮我解决这个问题吗


Tags: nameclientapi数据库falselocalhosthttp客户端