1

I have a problem to parse the "data" to data in curl command

curl -H "Content-Type: application/json" -X POST -d '{"data":"traffic cun cun je"}' http://68.xxx.236.113/api/

Above is my curl command. And after I use, https://curl.trillworks.com/ to convert curl command to Python, I got this

import requests
headers = {
    'Content-Type': 'application/json',
}
data = '{"data":"traffic cun cun je"}'
response = requests.post('http://68.xxx.236.113/api/', headers=headers, data=data)

The problem is, how can I change the "data":"CHANGE HERE" with the data in a list (text)

Below is my code for the list:

with open('hai.json') as f:
        data = json.load(f)

    for line in data:
        text=line['text']
        loc=line['location']
        i.append(text)
        u.append(loc)
Amzar
  • 23
  • 4
  • https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-inside-a-string-in-python – Heavy Octane Dec 06 '18 at 15:14
  • @Heavy Octane thank you, already tried with `data = urllib.parse.quote('{"data":"%s"}'%text)` , but i need the quote like this `'{"data":"apa la"}'` instead of `{"data":"apa la"}` – Amzar Dec 06 '18 at 15:42

0 Answers0