I wrote a simple flask app to parse XML requests and send a response. But when i try to parse the XML request, I get "unbound method get_data() must be called with Request instance as first argument (got nothing instead)".
I've tried variations of get_data with arguments according to https://werkzeug.palletsprojects.com/en/0.15.x/wrappers/#werkzeug.wrappers.BaseRequest.get_data' . I've also looked at a similar issue in SO, but that didn't help me.
from flask import Flask, Response, Request
import xmltodict
app = Flask(__name__)
@app.route("/")
def index():
return "Hello"
@app.route("/testapp", methods = ['POST'], strict_slashes=False)
def parseRequest():
content = xmltodict.parse(Request.get_data)
print content
if __name__ == "__main__":
app.run(host='0.0.0.0')
I send request using curl
curl -i -X POST "http://x.x.x.x:5000/testapp" -H "accept: application/xml" -H "Content-Type: text/xml" --data @test.xml
This is the content of the XML file.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
</soapenv:Header>
<soapenv:Body>
<com:qRequest xmlns:com=http://masked1
xmlns:xcom=http://masked2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<com:Query xsi:type="xcom:DynamicNamedQuery">
<xcom:Identifier>getDetails</xcom:Identifier>
<xcom:Parameters>
<paramvalue>ABCDE</paramvalue>
</xcom:Parameters>
</com:Query>
</com:qRequest>
</soapenv:Body>
</soapenv:Envelope>
This is the error I get - "TypeError: unbound method get_data() must be called with Request instance as first argument (got nothing instead)" . I've tried decoding it as utf8 as well, but I don't think that is the problem.
request.get_data()- with lowerrand()at the end.Requestis class name. Andrequestsis instance of classRequestwhich has all inforamtion from client.