1

I searched about our problem but couldn't find anny solution.

I've installed mysqlconnector in a virtual environment. I also changed the connection string from the sqlalchemy scaffold in pyramidsthat uses sqllite to connect, to our connection string using mysqlconnector:

sqlalchemy.url = mysql+mysqlconnector://admin:admin@127.0.0.1:3306/tetten

We use this code to initialise our database.

class Page(Base):
    """ The SQLAlchemy declarative model class for a Page object. """
    __tablename__ = 'pages'
    id = Column(Integer, primary_key=True)
    name = Column(String(40, convert_unicode=True), unique=True)
    data = Column(String(40, convert_unicode=True))

    def __init__(self, name, data):
        self.name = name
        self.data = data


class RootFactory(object):
    __acl__ = [ (Allow, Everyone, 'view'),
                (Allow, 'group:editors', 'edit') ]
    def __init__(self, request):
        pass

The table 'pages' is created in the database and also gets filled with the right data. When I go to my browser I get the following error:

**builtins.TypeError**
TypeError: embedded NUL character

with this output:

Traceback (most recent call last):
  File "c:\env\pyramid_debugtoolbar-1.0.4-py3.3.egg\pyramid_debugtoolbar\panels\performance.py", line 69, in noresource_timer_handler
    result = handler(request)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\tweens.py", line 21, in excview_tween
    response = handler(request)
  File "C:\env\lib\site-packages\pyramid_tm-0.7-py3.3.egg\pyramid_tm\__init__.py", line 82, in tm_tween
    reraise(*exc_info)
  File "C:\env\lib\site-packages\pyramid_tm-0.7-py3.3.egg\pyramid_tm\compat.py", line 13, in reraise
    raise value
  File "C:\env\lib\site-packages\pyramid_tm-0.7-py3.3.egg\pyramid_tm\__init__.py", line 63, in tm_tween
    response = handler(request)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\router.py", line 161, in handle_request
    response = view_callable(context, request)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\config\views.py", line 367, in rendered_view
    context)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\renderers.py", line 531, in render_view
    return self.render_to_response(response, system, request=request)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\renderers.py", line 561, in render_to_response
    result = self.render(value, system_values, request=request)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\renderers.py", line 557, in render
    result = renderer(value, system_values)
  File "C:\env\lib\site-packages\pyramid-1.4-py3.3.egg\pyramid\chameleon_zpt.py", line 42, in __call__
    result = self.template(**system)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 125, in __call__
    return self.render(**kwargs)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\zpt\template.py", line 257, in render
    return super(PageTemplate, self).render(**vars)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 169, in render
    self.cook_check()
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 293, in cook_check
    self.cook(body)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 147, in cook
    program = self._cook(body, digest, names)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 218, in _cook
    source = self._make(body, builtins)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\template.py", line 249, in _make
    program = self.parse(body)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\zpt\template.py", line 202, in parse
    trim_attribute_space=self.trim_attribute_space,
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\zpt\program.py", line 145, in __init__
    super(MacroProgram, self).__init__(*args, **kwargs)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\program.py", line 32, in __init__
    node = self.visit(kind, args)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\program.py", line 38, in visit
    return visitor(*args)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\zpt\program.py", line 270, in visit_element
    STATIC_ATTRIBUTES = self._create_static_attributes(prepared)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\zpt\program.py", line 790, in _create_static_attributes
    return Static(parse(repr(static_attrs)).body)
  File "C:\env\lib\site-packages\chameleon-2.11-py3.3.egg\chameleon\astutil.py", line 48, in parse
    return compile(source, '', mode, ast.PyCF_ONLY_AST)
TypeError: embedded NUL character

Does anny1 have a solution for my problem?

edit:

I found this link in the bug section of python. Altough I don't think it's a bug, this might be related to my problem. Can't seem to figure it out how it works tough. http://bugs.python.org/issue13617

4

2 回答 2

2

这与您的 SQLAlchemy 设置无关;这是您的模板引擎 (Chameleon) 编译成 Python 代码以提高速度和失败,因为您的模板中有一个 NUL 字符。

使用文本编辑器检查您的模板,并确保文件中没有不可打印的字节。

于 2013-02-22T10:18:07.780 回答
0

我无法在 Linux 上重现它。我的猜测是它是特定于 Windows 的,并且是 Python 中的一个错误。

于 2013-03-04T12:23:42.207 回答