Attribute 'type': The QName value '{http://www.w3.org/2001/XMLSchema}EmailString' does not resolve to a(n) type definition., line 4

StackOverflow https://stackoverflow.com/questions/22479354

  •  16-06-2023
  •  | 
  •  

Domanda

I want to extend spyne Unicode field with regex to ensure it is a valid E-Mail format. But even when copy-pasting basic example from spyne documentation http://spyne.io/docs/2.10/manual/03_types.html, I get the above error (see title) when visiting localhost/my-url-endpoint?wsdl.

I use Django 1.6 and Spyne 2.10.10. on Windows8 64-bit. Any suggestion why it fails?

The code:

from django.views.decorators.csrf import csrf_exempt
from spyne.protocol.soap import Soap11
from spyne.interface import Wsdl11
from spyne.service import ServiceBase
from spyne.decorator import srpc, rpc
from spyne.model.primitive import Unicode, Integer, Mandatory
from spyne.model.complex import Iterable
from spyne.application import Application
from spyne.server.django import DjangoApplication

class EmailString(Unicode):
    __type_name__ = 'EmailString'

    class Attributes(Unicode.Attributes):
        max_length = 128
        pattern = '[^@]+@[^@]+'

class MyService(ServiceBase):

    @rpc(EmailString, _returns=Unicode)
    def my_function(ctx, my_email):
        return "Your email is %s" % my_email

application = Application(
        [                  
            MyService
        ],
        tns="http://tempuri.org",
        interface=Wsdl11(),
        in_protocol=Soap11(validator='lxml'),
        out_protocol=Soap11()
)
myServiceApp = csrf_exempt(DjangoApplication(application))

MyServiceApp is then pointed to in urls.py:

urlpatterns += patterns('',
    (r'^my-url-endpoint$', 'myapp.views.myServiceApp'),
)

Stack trace:

Internal Server Error: /en/wsCRMService
Traceback (most recent call last):
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\handlers\base.py", line 101, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 320, in resolve
    sub_match = pattern.resolve(new_path)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 320, in resolve
    sub_match = pattern.resolve(new_path)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 320, in resolve
    sub_match = pattern.resolve(new_path)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 222, in resolve
    return ResolverMatch(self.callback, args, kwargs, self.name)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 229, in callback
    self._callback = get_callable(self._callback_str)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\utils\functional.py", line 32, in wrapper
    result = func(*args)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\core\urlresolvers.py", line 96, in get_callable
    mod = import_module(mod_name)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\django-1.6.1-py2.7.egg\django\utils\importlib.py", line 40, in import_module
    __import__(name)
  File "E:\my_project\myapp\views.py", line 146, in <module>
    out_protocol=Soap11()
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\spyne\application.py", line 104, in __init__
    self.in_protocol.set_app(self)
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\spyne\protocol\xml\_base.py", line 413, in set_app
    xml_schema.build_validation_schema()
  File "C:\Users\Anze\Virtual Environments\my_project\lib\site-packages\spyne\interface\xml_schema\_base.py", line 189, in build_validation_schema
    self.validation_schema = etree.XMLSchema(etree.parse(f))
  File "xmlschema.pxi", line 102, in lxml.etree.XMLSchema.__init__ (src\lxml\lxml.etree.c:154067)
XMLSchemaParseError: element decl. '{http://tempuri.org}my_email', attribute 'type': The QName value '{http://www.w3.org/2001/XMLSchema}EmailString' does not resolve to a(n) type definition., line 4

Please help.

È stato utile?

Soluzione

It will work if you do:

EmailString = Unicode(128, pattern='[^@]+@[^@]+', type_name="EmailStringType")

That pattern is just an example though, you can find better ones out there.

Altri suggerimenti

After hours of research I found out that it also works if you do class EmailString(Unicode(pattern='[^@]+@[^@]+')): __namespace__ = 'tempuri.org' __type_name__ = 'EmailString'

Is seems like meta class Attributes of EmailString should not be overwritten and then it works. Instead, you must put your customization in constructor of extended class (Unicode in this case)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top