wie die POST den Inhalt der JSON-Datei auf RESTFUL-API mit Python mithilfe Anfragen-Modul

Okay, ich gebe auf. Ich bin versucht zu posten, die den Inhalt einer Datei mit JSON. Der Inhalt der Datei sieht wie folgt aus:


{
     "id”:99999999,
     "orders":[
     {
             "ID”:8383838383,
             "amount":0,
             "slotID":36972026
     },
     {
             "ID”:2929292929,
             "amount":0,
             "slotID":36972026
     },
     {
             "ID”:4747474747,
             "amount":0,
             "slotID":36972026
     }]
}

Hier der code, was wahrscheinlich der Weg der Marke:

#!/usr/bin/env python3

import requests
import json

files = {'file': open(‘example.json’, 'rb')}
headers = {'Authorization' : ‘(some auth code)’, 'Accept' : 'application/json', 'Content-Type' : 'application/json'}

r = requests.post('https://api.example.com/api/dir/v1/accounts/9999999/orders', files=files, headers=headers)

InformationsquelleAutor Jeff F | 2015-02-01

Schreibe einen Kommentar