0

我试图在我的应用程序中加载一个页面,并弹出以下错误。我正在使用 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

视图.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))
4

1 回答 1

1

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

于 2012-05-10T20:30:30.327 回答