我在将请求发布到服务器时遇到问题。服务器重新调整了此错误“日期字段为必填”。但我已经将日期发布到服务器了。
ENDPOINT_URL = 'https://tash.example.com/api_v1/journal'
Header = {'Api-key': 'abc1234'}
with open('coa.csv', 'r') as csv_ledger:
r = csv.DictReader(csv_ledger)
data = [dict(d) for d in r]
groups = []
for k, g in groupby(data, lambda r:
(r['Code'],r['Description'],r['Account_Type_ID'])):
groups.append({
"date": "2018-10-10",
"name": "gfgfh",
"code": k[0],
"desc": k[1],
"account_type_id": k[2],
})
post_api = requests.post(ENDPOINT_URL, json=groups,headers=Header)
我怀疑是数据格式问题,所以我尝试了类似json=str(groups)
,json=json.dumps(groups)
,json=groups
之类的方法,但是它不起作用
这是我的标题日志
send: b'POST /api_v1/journal HTTP/1.1\r\nHost: tash.example.com\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nApi-key: 7cacadf4a6b695f8c493a80133e1813d\r\nContent-Length: 29189\r\n\r\n'
send: b"[{'date': '2018-10-10', 'name': 'gfgfh', 'code': '100-0000', 'desc': 'CAPITAL', 'account_type_id': ''}]
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Date: Sat, 12 Jan 2019 04:24:24 GMT
header: Content-Type: application/json
header: Content-Length: 62
header: Connection: keep-alive
header: Set-Cookie: AWSALB=cPiO/5gjlBMagQWkUF7T17+LZjyI649y4UeWTRqq7PQg1edQPC/VLOAneiPBM+9oMI8b16MhMd/iWXWy/MyL58SPErnVwq7XnLZa6PeaMaSkxn/azGseL6Qm6e4C; Expires=Sat, 19 Jan 2019 04:24:22 GMT; Path=/
header: Server: Apache
header: Cache-Control: no-cache
header: Set-Cookie: AWSALB=cPiO/5gjlBMagQWkUF7T17+LZjyI649y4UeWTRqq7PQg1edQPC/VLOAneiPBM+9oMI8b16MhMd/iWXWy/MyL58SPErnVwq7XnLZa6PeaMaSkxn/azGseL6Qm6e4C; Expires=Sat, 19 Jan 2019 04:24:22 GMT; Path=/
header: Content-Encoding: gzip
header: Vary: Accept-Encoding
header: X-UA-Compatible: IE=Edge,chrome=1