如何修复<响应 [400]>在 Python 中进行 POST 时? [英] How to fix <Response [400]> while make a POST in Python?
本文介绍了如何修复<响应 [400]>在 Python 中进行 POST 时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行脚本时,我一直在终端中收到
.
I kept getting <Response [400]>
in my terminal while running the script.
我试过了
import requests
import json
url = 'http://172.19.242.32:1234/vse/account'
data = '{
"account_id": 1008,
"email_address": "bhills_4984@mailinator.com",
"password": "qqq",
"account_type": "customer",
"name_prefix": "",
"first_name": "Beverly",
"middle_names": "",
"last_name": "Hills",
"name_suffix": "",
"non_person_name": false,
"DBA": "",
"display_name": "BeverlyHills",
"address1": "4984 Beverly Dr",
"address2": "4984 Beverly Dr",
"address3": "",
"city": "Beverly Hills",
"state": "CA",
"postal_code": "90210",
"nation_code": "90210",
"phone1": "3105554984",
"phone2": "",
"phone3": "",
"time_zone_offset_from_utc": -5,
"customer_type": "2",
"longitude": -118.4104684,
"latitude": 34.1030032,
"altitude": 0
}'
headers = {'content-type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers)
print r
<小时>
我做错了什么?
What did I do wrong ?
推荐答案
更改
r = requests.post(url, data=json.dumps(data), headers=headers)
到
r = requests.post(url, data=data, headers=headers)
因为data不是必须转成json的dict而是已经是json了.
because data is not a dict that must be transformed to json but is already json.
这篇关于如何修复<响应 [400]>在 Python 中进行 POST 时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文