【发布时间】:2013-02-06 23:13:17
【问题描述】:
我搜索了我们的问题,但找不到任何解决方案。
我已经在虚拟环境中安装了 mysqlconnector。我还将连接字符串从使用 sqllite 连接的金字塔中的 sqlalchemy 脚手架更改为使用 mysqlconnector 的连接字符串:
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
【问题讨论】:
标签: mysql python-3.x sqlalchemy pyramid mysql-connector