2017-04-03 2 views
-1

Flask를 사용하여 Restful 웹 서비스를 만들려고합니다. 하지만 GET 요청에서 xml 데이터를 처리하는 데 문제가 있습니다.Flask : GET 메서드에서 XML 처리

uri="http://127.0.0.1:5000/test/api/getfamilyinfo" 

request_body=''' 
<StayInfo> 
    <district>Khurda</district> 
    <village>BBSR</village> 
    <unit>Hogwarts</unit> 
</StayInfo> 
''' 

body_format = {'Content-Type': 'application/xml'} 

requests.get(uri, data = request_body, verify = False, headers = body_format) 

나는 점점 오전 오류 :

File &quot;C:\Python27\lib\xml\etree\ElementTree.py&quot;, line 647, in parse 
source = open(source, &quot;rb&quot;) 
TypeError: coercing to Unicode: need string or buffer, Response found</textarea> 

내 코드 :

@app.route('/test/api/getfamilyinfo', methods=['GET']) 
def getfamilyinfo(): 
    errors = [] 
    results = {} 

    if request.method == "GET": 
     try: 
      r=request.data 

     except Exception,e: 
      resp = jsonify({"error": str(e)}) 
      return resp, status.HTTP_400_BAD_REQUEST 

     if r: 
      eTree = ElementTree.parse(r) ## The code is breaking here 

가 친절하게 내가 잘못 가고 어디에 이해하는 데 도움이. 미리 감사드립니다.

답변

0

ElementTree.parse() (docs)은 파일 이름 (또는 파일 개체)을 필요로합니다.

당신이 원하는 ElementTree.fromstring() (docs).

+1

감사합니다. 알았다. 그것의 일 벌금. – May