Flask Api to parse xml post requests returning errors
You have to change you're curl request to be key=value pairs for easy handling.
Curl:
curl -H "Authorization: Bearer Token" -X POST -d 'SomeKey=<xml><From>Jack</From><Body>Hello, it worked!</Body></xml>' http://127.0.0.1:5000
Python:
from flask import Flask, jsonify, requestimport xmltodictapp = Flask(__name__)@app.route("/", methods=['GET', 'POST'])def parse_xml(): xml_data = request.form['SomeKey'] content_dict = xmltodict.parse(xml_data) return jsonify(content_dict)
Response:
{ "xml": { "Body": "Hello, it worked!", "From": "Jack" }}