Unsere API-Clients unterstützen nur das Format multipart/form-data und application/x-www-form-urlencoded. Also, wenn ich versuche, ihre API zuzugreifen:Wie geht es weiter mit multipart/form-data oder application/x-www-form-urlencoded Anfrage mit Requests Modul in Python?
import requests
import json
url = "http://api.client.com/admin/offer"
headers = {"Content-Type": "multipart/form-data", "API-Key": "ffffffffffffffffffffffffffffffffffffffff"}
data = {"Content-Type": "multipart/form-data", "title": "Demo offer", "advertiser": "f4a89a7h1aq", "url": "http://demo.com/", "url_preview": "http://demo.com/", "description": "Bla bla bla", "freshness": "fresh", "total": "2.0", "revenue": "1.8"}
r = requests.post(url, headers=headers, data=json.dumps(data))
print r.text
ich diese:
{"status":2,"error":"Submitted wrong data. Check Content-Type header"}
Wie dieses Problem zu überwinden?
Danke!
Vielen Dank, dass Sie bemerkt haben, dass ich json.dumps() nicht aus meinem Code entfernt habe. Das Problem war damit :-) – paus