[CPyUG:61182] GAE邮件问题中文编码问题求助

View: New views
2 Messages — Rating Filter:   Alert me  

[CPyUG:61182] GAE邮件问题中文编码问题求助

by Meaglith Ma-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys:
    我从Flash里面向GAE的一个表单post数据,Flash里面的文字发出肯定是UTF-8编码,我调用db model进行保存,不需要encode都能保存成功,未有编码错误。但是发送邮件的时候,设置subject和html body的时候总是报编码错误。

错误信息:
  UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-6: ordinal not in range(128)

  取得表单参数的是这样写的: self.request.get("body") self.request.get("subject")

  py文件已经设置utf-8编码。

Thanks

--~--~---------~--~----~------------~-------~--~----~
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:python-cn@...
退订: http://tinyurl.com/45a9tb /针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: http://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
-~----------~----~----~----~------~----~------~--~---


[CPyUG:61228] Re: GAE邮件问题中文编码问题求助

by Lin Sheng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>     我从Flash里面向GAE的一个表单post数
> 据,Flash里面的文字发出肯定是UTF-8编
> 码,我调用db model进行保存,不需要encode都能保
> 存成功,未有编码错误。但是发送邮件的时候,设置subject
> 和html body的时候总是报编码错误。
>
> 错误信息:
>   UnicodeEncodeError: 'ascii' codec can't encode characters in  
> position 5-6: ordinal not in range(128)
>
>   取得表单参数的是这样写的:  
> self.request.get("body") self.request.get("subject")
>
>   py文件已经设置utf-8编码。
>

把邮件的标题和正文字符串encode一下。例如:subject.encode('utf8')

---------------
http://www.onlypython.com/




--~--~---------~--~----~------------~-------~--~----~
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:python-cn@...
退订: http://tinyurl.com/45a9tb /针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: http://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!