2016-10-10 7 views
0

@service.xmlデコレータがweb services RPCに分割されているようです。Webサービスで無効なXMLコードが生成されました

@service.xml 
def concat(a, b): 
    return a + b 

結果は次のとおりです。

>>> from urllib import urlopen 
>>> r = urlopen("http://127.0.0.1:8000/webservice/default/call/xml/concat/hello/ 
world") 
>>> r.read() 
'<?xml version="1.0" encoding="UTF-8"?>helloworld' 

最後の部分は無効なXMLを生成する欠落です。

ただし、JSONとCSVは正常に動作します。

@service.json 
def concat(a, b): 
    return a + b 

テスト:

>>> r = urlopen("http://127.0.0.1:8000/webservice/default/call/json/concat/hello 
/world") 
>>> r.read() 
'"helloworld"' 

私は足場のアプリケーションのコピーでこれをテストしています。私は何かを逃しているのですか、これは本当に問題ですか?

答えて

1

私はそれが本の単なる悪い例だと思います。有効なXMLを生成するには、関数がリストまたはディクショナリ(または.as_list.as_dict、または.custom_xmlメソッドを持つオブジェクト)を返す必要があります。例えば:

@service.xml 
def concat(a, b): 
    return dict(result=a + b) 

が生成:

<?xml version="1.0" encoding="UTF-8"?> 
<document> 
    <result>helloworld</result> 
</document> 
関連する問題