ajdavis / motor-blog

Blog based on Tornado, MongoDB, and Motor. To be used with MarsEdit.
148 stars 40 forks source link

there are some decoding errors about supporting chinese display #38

Open versionzhang opened 8 years ago

versionzhang commented 8 years ago

@ajdavis Hi, I have deploy the blog on my vps,I found some errors about decoding chinese chars.

If the blog description contains non-ascii chars, it will raise exceptions.

the error message:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1445, in _execute
    result = yield result
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "/home/tornado_blog/motor-blog/motor_blog/web/handlers.py", line 323, in get
    this_tag=tag, page_num=int(page_num))
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 282, in wrapper
    yielded = next(result)
  File "/home/tornado_blog/motor-blog/motor_blog/web/handlers.py", line 93, in render_async
    template_name, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 806, in render_string
    return t.generate(**namespace)
  File "/usr/local/lib/python2.7/dist-packages/tornado/template.py", line 345, in generate
    return execute()
  File "tag_jade.generated.py", line 5, in _tt_execute
    title = setting('author_display_name') + " | " + this_tag  # tag.jade:1 (via base.jade:1)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 9: ordinal not in range(128)

And if your tags contain chinese chars,it will show these messages.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1445, in _execute
    result = yield result
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "/home/tornado_blog/motor-blog/motor_blog/web/handlers.py", line 253, in get
    categories=categories)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 282, in wrapper
    yielded = next(result)
  File "/home/tornado_blog/motor-blog/motor_blog/web/handlers.py", line 93, in render_async
    template_name, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 806, in render_string
    return t.generate(**namespace)
  File "/usr/local/lib/python2.7/dist-packages/tornado/template.py", line 345, in generate
    return execute()
  File "single_jade.generated.py", line 231, in _tt_execute
    _tt_tmp = __pyjade_attrs(attrs=[('href',(reverse_url('tag', tag))), ('title',("All posts tagged "+"{}".format( tag )+""))])  # single.jade:5 (via base.jade:28)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
versionzhang commented 8 years ago

The same thing about decode in Chinese. If the title using Chinese, I can't get a right url.

You can visit

http://www.versionzhang.com/blog/

then you click the only one article.

It takes you to this link.

http://www.versionzhang.com/blog//

And if you want to add one new article with Chinese title, marsedit will get errors.

Can’t post for blog site because the server reported an error: E11000 duplicate key error collection: motorblog.posts index: slug_1 dup key: { : "" }.

I think it is the same error about non-ascii chars support.

versionzhang commented 8 years ago

I have fixed the problem.l will pull the request for it tonight.