为什么 Markdown 在我导出的 WordPress xml 文件中发现奇怪的字符?
Mac OS X 10.7 Python 2.7 姜戈1.3 Markdown 2.0.3
我正在尝试从 WordPress 博客迁移到 django 支持的博客。我使用pigmonkey的django-basic-apps作为它的xml解析脚本,但是每次我尝试一下,markdown 不断引发“markdown.MarkdownException: UnicodeDecodeError: Markdown 仅接受 unicode 或 ascii 输入。”
完整的回溯:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/management/commands/wordpress_import.py", line 100, in handle
post.save()
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/models.py", line 77, in save
self.body_rendered = mark_safe(formatter(self.body_rendered, filter_name=self.markup))
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/markup.py", line 90, in __call__
return filter_class().render(text, **filter_kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/filter/markdown_filter.py", line 21, in render
text = markdown(text, **kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 598, in markdown
return md.convert(text)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 377, in convert
message(CRITICAL, 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.')
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 112, in message
raise MarkdownException, text
markdown.MarkdownException: UnicodeDecodeError: Markdown only accepts unicode or ascii input.
除了unicode之外没有任何东西,我发现也许你们会有更好的运气。
我也可以上传 xml 文件,如果有帮助的话
Mac OSX 10.7
Python 2.7
Django 1.3
Markdown 2.0.3
I am trying to migrate from a wordpress blog to a django-powered one. I am using pigmonkey's django-basic-apps for it's xml parsing script, but every time I attempt it, markdown keeps raising "markdown.MarkdownException: UnicodeDecodeError: Markdown only accepts unicode or ascii input."
Full traceback:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/management/commands/wordpress_import.py", line 100, in handle
post.save()
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/models.py", line 77, in save
self.body_rendered = mark_safe(formatter(self.body_rendered, filter_name=self.markup))
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/markup.py", line 90, in __call__
return filter_class().render(text, **filter_kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/filter/markdown_filter.py", line 21, in render
text = markdown(text, **kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 598, in markdown
return md.convert(text)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 377, in convert
message(CRITICAL, 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.')
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 112, in message
raise MarkdownException, text
markdown.MarkdownException: UnicodeDecodeError: Markdown only accepts unicode or ascii input.
There's nothing outside unicode in there, that I've found maybe you guys would have better luck.
I can upload the xml file too, if that would help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题应该在我最近提交 django-basic-apps 分支时得到修复。该错误是由于在将帖子正文传递给 Markdown 之前传递帖子正文并通过内联解析器进行梳理而引起的(这对于 其他原因)。我不完全理解为什么会抛出错误,但是您可以阅读今天的提交消息以了解我所知道的内容:
https://github.com/pigmonkey/django-vellum/commit/1d5fb4743a7fc34e4b6cd415144ad232bbc3f0ad
顺便说一句,我今天刚刚注意到这个问题,因为我正在做一些谷歌搜索,试图理解这个错误。为了将来的参考,如果您通过 Github 或通过我的网站联系我,或者在 Github 上为该项目创建一个问题,或者给我发电子邮件,我可能会回复得更快!我总是有兴趣了解我的项目中发现的任何错误。
This should be fixed as of my most recent commit to my fork of django-basic-apps. The error was caused by passing the post's body and tease through the inline parser before passing it to Markdown (which is necessary for other reasons). I don't fully understand why the error was being thrown, but you can read today's commit message for what I do know:
https://github.com/pigmonkey/django-vellum/commit/1d5fb4743a7fc34e4b6cd415144ad232bbc3f0ad
By the way, I just noticed this question today as I was doing some Googling, trying to understand this error. For future reference, if you contact me through Github, or through my website, or create an Issue for the project on Github, or email me, I'll probably respond a lot faster! I'm always interested to hear about any bugs found in my projects.