python3.3 TypeError:嵌入的NUL字符

时间:2013-02-21 15:03:56

标签: mysql python-3.x sqlalchemy pyramid mysql-connector

我搜索了我们的问题,但找不到解决方案。

我在虚拟环境中安装了mysqlconnector。我还使用sqllite来连接到使用mysqlconnector连接到我们的连接字符串的pyramid中的sqlalchemy脚手架中的连接字符串:

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

我们使用此代码初始化我们的数据库。

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

表'pages'在数据库中创建,并且还填充了正确的数据。 当我进入浏览器时出现以下错误:

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

使用此输出:

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

anny1能解决我的问题吗?

编辑:

我在python的bug部分找到了这个链接。尽管我不认为这是一个错误,这可能与我的问题有关。似乎无法弄清楚它是如何运作的。 http://bugs.python.org/issue13617

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

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