Search code examples
pythonpython-requestsdata-transfer

Send multipart/form-data string with POST requests, python


I want to send a string through POST request like

#my data string
data='[{ "DeviceNo":"123123123","LogDate":"2018-11-18", "FileName":"X.py", "LogMessage":"Message" }]'

response = requests.post(url,files=data, timeout=20, headers={'Authorization': accessToken}) 

I dont know how to send this data. Don't know if "files=data" is a correct usage for that.


Solution

  • following code is the solution for me. Hope it help someone (i lost so much time on this one)

    data={
      "request":"{ 'action':'CreateLog', 'version':'1', 'parameters': { 'Message':'my message'}}" 
         }
    response = requests.post(url,data=data, timeout=20, headers={'Authorization': accessToken})