我正在尝试使用Python3复制PUT请求。我需要发送的表单数据在Firefox中如下所示:
而且在Chrome中是这样的:
我尝试了以下操作:
explanation_data = user_a1.put(
f"/review/{card_id}/verify", f"answerIds%5B%5D={answer1_id}&answerIds%5B%5D={answer2_id}"
)
explanation_data = user_a1.put(
f"/review/{card_id}/verify", {
"answerIds":[answer1_id],
"answerIds":[answer2_id]
}
)
explanation_data = user_a1.put(
f"/review/{card_id}/verify", {
"answerIds":[answer1_id,answer2_id]
}
)
explanation_data = user_a1.put(
f"/review/{card_id}/verify", {
"answerIds":[answer1_id],
"answerIds":[answer2_id]
}
)
然后下面的代码可以正常运行:
explanation_data = user_a1.put(
f"/review/{card_id}/verify", {
"answerIds":[answer2_id]
}
)
我确定这是很明显的事情。我要去哪里错了?
使用requests==2.6.2
,下面是使用您希望的URL进行PUT请求的示例python代码。
import requests
headers = {'Content-Type': 'application/json'}
url = "http://localhost:5000"
params = (
('answerIds', ['1234', '5678']),
)
req = requests.put(url, params=params, headers=headers)
print req.status
[当我为上述请求服务器端打印URL时。下面是输出。
http://localhost:5000/?answerIds=1234&answerIds=5678
希望这会有所帮助。