1

try post to API with python :

import requests
import json

url='https://link.html'

data = {
'keyfile':{
'valuekey1': 'data1',
'valuekey2': 'data2'
}
}

payload = {'keypost': data}

headers = {
'Authorization': 'Bearer <token>',
#'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
}

response = requests.post(url, headers=headers, data=payload)

print(response)
print(response.text)

in API catch multipart form data with key "keypost" then get json with "keyfile" but the "keypost" and "keyfile" can't catch on API, what i'm wrong when send post data in python requests ?

[UPDATE] try to change payload with this and successfull:

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"keypost\"\r\n\r\n{\"keyfile\": {\"valuekey1\": \"data1\", \"valuekey2\":\"data2\"}}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

whats diferent payload 1 and payload 2:

  1. data = {
    'keyfile':{
    'valuekey1': 'data1',
    'valuekey2': 'data2'
    }
    }
    
    payload = {'keypost': data}
    
  2. ------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"keypost\"\r\n\r\n{\"keyfile\": {\"valuekey1\": \"data1\", \"valuekey2\":\"data2\"}}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--
    

but i want still payload 1 because look simple ?

blinkbink
  • 89
  • 5

1 Answers1

0

try this :

data = {
    'valuekey1': 'data1',
    'valuekey2': 'data2'
}

payload = {'keypost': data}
Saeed Gholamzadeh
  • 932
  • 1
  • 6
  • 22
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Igor F. Mar 11 '20 at 09:22