python - 请求发布字典格式错误的数据
问题描述
我无法将其正确发布到服务器。我试过这样:
payload = {
"ad_id": ad_id,
"ad_type": "1",
"csrf_token": crsf_token,
"messages": [{'content': 'message to server', 'message_type': 'text'}],
"user_id": "9020446"
}
#
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Type": "application/json",
"Origin": "https://www.wg-gesucht.de",
"Referer": f"https://www.wg-gesucht.de/nachricht-senden.html?message_ad_id={ad_id}"
}
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', payload, headers=headers)
我也这样尝试过:
"messages": ['message to server']
但我总是收到 401 错误。
如果有人可以帮助我,那就太好了。
此致!
解决方案
我刚刚将 posttype 更改为“json”,这为我修复了错误:
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', json=payload, headers=headers)
还是谢谢你们的帮助。
推荐阅读
- python - 找到一种在 Python 函数中的所有元素之间使用减法的方法
- javascript - Vue:在路线更改时,仅在完成加载后才呈现页面
- pandas - 在熊猫中提取周时面临日期错误
- excel - 用包含数据结构的数组填充的数组
- c++ - 如何在 C++ 中修复退出值 -1,073,741,701
- spring-boot - Spring boot (2.0.3) 与 Apache Ignite (2.7) Spring 依赖冲突
- laravel - 在同一个表格单元格中显示相同的值
- mysql - 如何将基本的 mysql 查询(相关表)更改为 Laravel?
- javascript - 再次加入拆分后的字符串,跳过拆分后形成的数组的一个索引
- rxjs - combineLatest2 只有第一个非空流输出