python - TeamViewer API 和 PostMan

标签 python api teamviewer

我正在寻找一种使用 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"))

如何使用多个有效负载执行此操作?

最佳答案

这应该可以解决问题:

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"))

您只需要以某种方式用您的实际数据初始化/填充idspws 并且它们显然需要具有相同的大小(pws 上的密码 属于ids 中同一位置的id)。

关于python - TeamViewer API 和 PostMan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33616968/

相关文章:

c# - 如何使用 C#/pinvoke 将输入发送到 WinSta0\Winlogon 桌面

javascript - Teamviewer 与 JNDI 冲突 - 为传出使用更高的端口号 (win7)

python - 重命名数据帧中的索引子集

python - 如何解析div中的表格

python - 重定向时 Kivy screenmanager "No Screen with name"错误

python - Freebase API 获取其他类型的查询

ios - 如何将 iOS 11 控制中心中的屏幕截图转发到您的应用程序?

python - 如何将Python中的模块导入到既用作 __main__ 又由不同目录中的文件导入的文件中?

mysql - 将Json文件API转为MySQL数据表

api - Angular 2,API 模型的 typescript 发布为空