Python Forum

Full Version: Modify XML request on Flask with ElementTree
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm python beginner. What I wan't to solve, is modify POST request(xml via cURL) on Flask. Thank's for anny help.

Simple server code:
from flask import Flask, request
import xml.etree.ElementTree as etree


app = Flask(__name__)


@app.route("/test", methods=['GET', 'POST'])
def r_xml():
    xml_data = request.form['TEST']
    tree = etree.parse(xml_data)
    root = tree.getroot()
    attrib = {}
    element = root.makeelement('NEWITTEM', attrib)
    root.append(element)
    return xml_data
cURL request:

curl -X POST http://127.0.0.1:5000/test -d "TEST=<xml><Name1>MyName</Name1><Name2>YourName</Name2></xml>"

I get this error code:

OSError: [Errno 22] Invalid argument