0

我想使用flask-Enterprise,但找不到任何文档或示例。如果我想返回原始类型,这很容易,但如果我想返回类,我就无法做到这一点。

from soaplib.core.model.clazz import ClassModelBase
from flaskext.enterprise import Enterprise
from flask import Flask, render_template

#config Flask Enterprise
enterprise = Enterprise(app)
String = enterprise._sp.String
Integer = enterprise._sp.Integer
Boolean = enterprise._sp.Boolean
Array = enterprise._scls.Array

class T(ClassModelBase):
  date=""
  time=""

class Service(enterprise.SOAPService):
  """Soap Service Class

 Attributes:
    __soap_target_namespace__ : namespace for soap service
    __soap_server_address__ : address of soap service
  """
  __soap_target_namespace__ = 'TNS'
  __soap_server_address__ = '/soap'

@enterprise.soap(String, _returns=Integer)
def reg(self, strIdent):
  """ 
  Args:
    strIdent : string
  Returns:
    retrurn an int
  """
  return 1

@enterprise.soap(String,_returns=Array(T))
def getT(self, strIdent):
    """ 
    Args:
        strIdent : string

    Returns:
        return an array of classes
    """
    arr=[]
    arr.append(T(date="12.09.", time="17:00"))
    arr.append(T(date="13.09.", time="18:00"))
    return arr

服务注册正常工作,服务 getT 有错误

[Tue Aug 25 17:35:01 2015] [error] [client #######] mod_wsgi (pid=#####): Target WSGI script '/###/#####.wsgi' cannot be loaded as Python module.
[Tue Aug 25 17:35:01 2015] [error] [client #######] mod_wsgi (pid=#####): Exception occurred processing WSGI script '/###/#####.wsgi'.
[Tue Aug 25 17:35:01 2015] [error] [client #######] Traceback (most recent call last):
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/###/#####.wsgi", line 5, in <module>
[Tue Aug 25 17:35:01 2015] [error] [client #######]     from t.app import app as application
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/###/#####.wsgi", line 28, in <module>
[Tue Aug 25 17:35:01 2015] [error] [client #######]     class Service(enterprise.SOAPService):
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/flaskext/enterprise.py", line 104, in __new__
[Tue Aug 25 17:35:01 2015] [error] [client #######]     self.controller.register_soap_service(rv)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/flaskext/enterprise.py", line 45, in register_soap_service
[Tue Aug 25 17:35:01 2015] [error] [client #######]     soap_app = Application([service], service.__soap_target_namespace__)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/_base.py", line 317, in __init__
[Tue Aug 25 17:35:01 2015] [error] [client #######]     self.schema =  self.build_schema()
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/_base.py", line 686, in build_schema
[Tue Aug 25 17:35:01 2015] [error] [client #######]     inst = self.get_service(s)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/_base.py", line 727, in get_service
[Tue Aug 25 17:35:01 2015] [error] [client #######]     return service(http_req_env)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/service.py", line 296, in __init__
[Tue Aug 25 17:35:01 2015] [error] [client #######]     _public_methods_cache[cls] = self.build_public_methods()
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/service.py", line 384, in build_public_methods
[Tue Aug 25 17:35:01 2015] [error] [client #######]     descriptor = func(_method_descriptor=True, clazz=self.__class__)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/service.py", line 176, in explain_method
[Tue Aug 25 17:35:01 2015] [error] [client #######]     kparams
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/service.py", line 90, in _produce_rpc_output_message
[Tue Aug 25 17:35:01 2015] [error] [client #######]     message.resolve_namespace(message, ns)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/model/clazz.py", line 266, in resolve_namespace
[Tue Aug 25 17:35:01 2015] [error] [client #######]     v.resolve_namespace(v, default_ns)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/model/clazz.py", line 389, in resolve_namespace
[Tue Aug 25 17:35:01 2015] [error] [client #######]     serializer.resolve_namespace(serializer, default_ns)
[Tue Aug 25 17:35:01 2015] [error] [client #######]   File "/usr/local/lib/python2.7/dist-packages/soaplib/core/model/clazz.py", line 260, in resolve_namespace
[Tue Aug 25 17:35:01 2015] [error] [client #######]     for k, v in cls._type_info.items():
[Tue Aug 25 17:35:01 2015] [error] [client #######] AttributeError: type object 'Tips' has no attribute '_type_info'
4

1 回答 1

0

将类 T 声明为(我希望日期和时间是字符串,否则将其替换为任何原始类型)

from soaplib.core.model.clazz import ClassModel

class T(ClassModel):
  date = String
  time = String

并且您的其余代码是正确的。它应该工作

于 2015-08-26T13:17:21.100 回答