Django中的UnicodeEncodeError

时间:2012-05-10 20:26:31

标签: python django

我尝试在我的应用中加载页面,然后弹出以下错误。我用tweepy连接到twitter。我不知道错误来自哪里或我需要解决的问题。很想知道如何解决这个问题。

  UnicodeEncodeError at /test/

   'charmap' codec can't encode character u'\u2019' in position 6: character maps to   <undefined>

   Request Method:      GET
   Request URL:     http://127.0.0.1:8000/test/
   Django Version:  1.3.1
   Exception Type:  UnicodeEncodeError
   Exception Value: 'charmap' codec can't encode character u'\u2019' in position 6: character maps to <undefined>
  Exception Location:   C:\Python27\lib\encodings\cp437.py in encode, line 12
  Python Executable:    C:\Python27\python.exe
  Python Version:   2.7.2

Views.py

  def testdat(request):
      if request.method=="GET":
         treats=Cursor(api.list_timeline, owner=request.user, slug="").items(20)
         for treat in treats:
             print "%s\t%s\t%s\t%s" % (treat.text,
                                  treat.author.screen_name,
                                  treat.created_at,
                                  treat.source,)
             top=Twet(text= treat.text, author_screen_name= treat.author.screen_name, created_at= treat.created_at, source= treat.source)
             top.save()
        treats=Cursor(api.list_timeline, owner=request.user, slug='').items(20)
        return render_to_response('dashy.html',{'treats': treats},context_instance=RequestContext(request))

1 个答案:

答案 0 :(得分:1)

停止打印。找出一种不同的调试方法。或者,首先编码为UTF-8。