使用py请求HTTP post请求时出现问题

问题描述 投票:0回答:2

我在从此 API 请求 POST 请求时遇到问题:https://docs.pixe.la/entry/post-user

import requests as re
url = 'https://pixe.la/v1/users'
myobj =({"token":"tonybui", 
        "username":"Tonybui2003", 
        "agreeTermsOfService":"yes", 
        "notMinor":"yes"})
        
# {"message":"Success. Let's visit https://pixe.la/@a-know , it is your profile page!","isSuccess":true}
response = re.post(url, data = myobj)

# data = response.json()
print(response.text)

错误信息:

{"message":"Failed to unmarshal request body: invalid character 'o' in literal true (expecting 'r')","isSuccess":false}

python-3.x
2个回答
0
投票

代替

response
变量中的 data = myobj 使用
json = myobj

删除myobj变量中的括号


0
投票

错误可能是因为您的 request=>response = request.post(url=url, json= myobj)

© www.soinside.com 2019 - 2024. All rights reserved.