我正在尝试通过 API 发送数据,但收到 TypeError: can't concat bytes to str. 我理解这意味着我需要将部分代码转换为字节,但我不确定如何执行此操作。我尝试在前面添加 b 或使用 bytes('data') 但可能将它们放在错误的区域。
import http.client
conn = http.client.HTTPSConnection("exampleurl.com")
payload = {
'FilterId': "63G8Tg4LWfWjW84Qy0usld5i0f",
'name': "Test",
'description': "Test1",
'deadline': "2017-12-31",
'exclusionRuleName': "Exclude",
'disable': "true",
'type': "Type1"
}
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'x-csrf-token': "wWjeFkMcbopci1TK2cibZ2hczI",
'cache-control': "no-cache",
'postman-token': "23c09c76-3b030-eea1-e16ffd48e9"
}
conn.request("POST", "/api/campaign/create", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
这是问题行:
conn.request("POST", "/api/campaign/create", payload, headers)
我不确定什么以及如何转换为字节。