2

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.

2
  • it should be rather request.get_data() - with lower r and () at the end. Commented Aug 25, 2019 at 19:18
  • Request is class name. And requests is instance of class Request which has all inforamtion from client. Commented Aug 25, 2019 at 19:19

1 Answer 1

2

Working code. Just wrong uses of classes in your case

import xmltodict
from flask import Flask, request

app = Flask(__name__)
@app.route("/")
def index():
    return "Hello"

@app.route("/testapp", methods = ['POST', 'GET'], strict_slashes=False)
def parseRequest():
    content = xmltodict.parse(request.get_data())
    print (content)
    return content


if __name__ == "__main__":
    app.run(host='0.0.0.0')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.