Python 中作为 PUT 请求的表单输入(数组)
Form Input (Array) as PUT request in Python
我正在尝试使用 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
,下面是示例 python 代码,用于根据您的需要 URL.
发出 PUT 请求
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
希望对您有所帮助。
我正在尝试使用 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
,下面是示例 python 代码,用于根据您的需要 URL.
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
希望对您有所帮助。