我有这个 curl ,我正试图在 python 中工作。我的问题是,有一个 --data-binary $'{\"streamerId\":\"u75aa923027266ec9ec4f0857ef0e22d3\"}'\
我不知道如何发布。
有效的 curl 是:
curl -i -s -k -X $'POST' \
-H $'Accept-Language: en' -H $'User-Agent: CastService/2.8.2 Android/6.0 Burp_Pen_Testing' -H $'X-Line-Live-AccessToken: dAGvdW_0jh1zyPo5oxIOoUtQ9wN__Z_QpbB0WicyRRTc0BM_D55vRUSu1K3wtZzYwgjzeSuVAAABcoThJOM' -H $'X-Line-Live-PushToken: d34hWbzL4bA:APA91bF_dMmD1WSWuCtBIxnMoeO1fo8fUQIACsUu2nEwQrl-ZsWvB45WA2tk4gpGSf9V9Ep4dyhdj94b0dSKv2RknDYBDuJU_Qa1X7wSqgWiOrDcxDGzAGGORC5v2md7rG-0iaSSW8VN' -H $'X-Line-Live-PushType: GCM' -H $'X-Line-Live-PushSetting: allMessages' -H $'X-Line-Live-TimeZoneId: America/New_York' -H $'X-Line-Live-Country: DK' -H $'X-Line-Live-Adid: 8dee9a2c-29b2-4da8-b76f-ab19f7ef4df2' -H $'Content-Type: application/json; charset=UTF-8' -H $'Content-Length: 50' -H $'Host: api.linelive.me' -H $'Connection: close' -H $'Accept-Encoding: gzip, deflate' \
--data-binary $'{\"streamerId\":\"u75aa923027266ec9ec4f0857ef0e22d3\"}' \
$'https://api.linelive.me/api/v1.4/user/follow'
我通过自动 curl 到 python 并得到:
import requests
headers = {
'Accept-Language': 'en',
'User-Agent': 'CastService/2.8.2 Android/6.0 Burp_Pen_Testing',
'X-Line-Live-AccessToken': 'dAGvdW_0jh1zyPo5oxIOoUtQ9wN__Z_QpbB0WicyRRTc0BM_D55vRUSu1K3wtZzYwgjzeSuVAAABcoThJOM',
'X-Line-Live-PushToken': 'd34hWbzL4bA:APA91bF_dMmD1WSWuCtBIxnMoeO1fo8fUQIACsUu2nEwQrl-ZsWvB45WA2tk4gpGSf9V9Ep4dyhdj94b0dSKv2RknDYBDuJU_Qa1X7wSqgWiOrDcxDGzAGGORC5v2md7rG-0iaSSW8VN',
'X-Line-Live-PushType': 'GCM',
'X-Line-Live-PushSetting': 'allMessages',
'X-Line-Live-TimeZoneId': 'America/New_York',
'X-Line-Live-Country': 'US',
'X-Line-Live-Adid': '8dee9a2c-29b2-4da8-b76f-ab19f7ef4df2',
'Content-Type': 'application/json; charset=UTF-8',
'Content-Length': '50',
'Host': 'api.linelive.me',
'Connection': 'close',
'Accept-Encoding': 'gzip, deflate',
}
data = '{\\"streamerId\\":\\"u75aa923027266ec9ec4f0857ef0e22d3\\"}'
response = requests.post('https://api.linelive.me/api/v1.4/user/follow', headers=headers, data=data, verify=False)
我尝试过以各种方式进行更改,例如删除“http://$”和更改数据字符串。但我好像做不对,为什么我现在向你求助。
提前感谢您的帮助。
最佳答案
如果您尝试在负载中传递 JSON 值,请使用 json
关键字参数:
# A plain dict; requests will serialize it to JSON for you
data = {"streamerId": "u75aa923027266ec9ec4f0857ef0e22d3"}
response = requests.post(
'https://api.linelive.me/api/v1.4/user/follow',
headers=headers,
<b>json=data</b>,
verify=False
)
使用 json
是 data=json.dumps(data)
的缩写。
关于python - 如何将这个带有二进制数据的 curl 写入 python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62218885/