我正在寻找一种使用python中的postman片段解析多个API请求的方法。
以下工作:
import http.client
conn = http.client.HTTPSConnection("webapi.teamviewer.com")
payload = "remotecontrol_id=rxxxxxxxx&groupid=g18932019&alias=test1%20api&password=xxxxxx"
headers = {
'authorization': "Bearer xxxxxxx-xxxxxxxxxxx",
'cache-control': "no-cache",
'postman-token': "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
'content-type': "application/x-www-form-urlencoded"
}
conn.request("POST", "/api/v1/devices", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
我如何在多个有效载荷下做到这一点?
发布于 2015-11-10 08:22:02
这应该能起作用:
import http.client
conn = http.client.HTTPSConnection("webapi.teamviewer.com")
headers = {
'authorization': "Bearer xxxxxxx-xxxxxxxxxxx",
'cache-control': "no-cache",
'postman-token': "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
'content-type': "application/x-www-form-urlencoded"
}
ids = [35123241, 234234234, 1232312, 5644352, 234243234]
pws = ["47gj6", "fgdg6as", "saa23d", "a24asd", "gre42as"]
for i in range(len(ids)):
payload = "remotecontrol_id=r%s&groupid=g18932019&alias=%s&password=%s" % (ids[i], ids[i], pws[i])
conn.request("POST", "/api/v1/devices", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
您只需要用实际数据初始化/填充ids
和pws
,它们显然需要相同的大小( pws
上的密码属于位于同一位置的ids
中的in )。
https://stackoverflow.com/questions/33616968
复制相似问题