2

I have this curl that I am trying to make work in python. My problem is, that there is a --data-binary $'{\"streamerId\":\"u75aa923027266ec9ec4f0857ef0e22d3\"}' \ which I don't know how to POST.

The curl which works is:

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'

I put it through an automatic curl to python and got:

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)

I've tried to change things like removing the "http://$" and changing the data string in various ways. But I can't seem to get it right, why I now ask you for help.

In advance, thank you for your kind help.

2
  • What exactly is the problem/error? Also you're dealing with a json payload, not binary data. Commented Jun 9, 2020 at 18:40
  • Even the curl looks overly complicated: why not --data '{"streamerId": ...}'? Commented Jun 9, 2020 at 19:05

2 Answers 2

5
+50

If you are trying to pass a JSON value in the payload, use the json keyword argument:

# 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,
    json=data, 
    verify=False
)

Using json is short for data=json.dumps(data).

Sign up to request clarification or add additional context in comments.

Comments

0

chepner's answer is correct but if you want another alternative for some reason, remove the escaping from your data string

data = '{"streamerId": "u75aa923027266ec9ec4f0857ef0e22d3"}'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.