嗨,你能不能幫我解碼此消息,並做什麼:我如何理解這個python錯誤信息?
main.py", line 1278, in post
message.body = "%s %s/%s/%s" % (msg, host, ad.key().id(), slugify(ad.title.encode('utf-8')))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
由於已經試圖消除編碼
更新調用它似乎工作:
class Recommend(webapp.RequestHandler):
def post(self, key):
ad= db.get(db.Key(key))
email = self.request.POST['tip_email']
host = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])
senderemail = users.get_current_user().email() if users.get_current_user() else '[email protected]' if host.endswith('.cl') else '[email protected]' if host.endswith('.mx') else '[email protected]' if host.endswith('.br') else '[email protected]'
message = mail.EmailMessage(sender=senderemail, subject="%s recommends %s" % (self.request.POST['tip_name'], ad.title))
message.to = email
message.body = "%s %s/%s/%s" % (self.request.POST['tip_msg'],host,ad.key().id(),slugify(ad.title))
message.send()
matched_images=ad.matched_images
count = matched_images.count()
if ad.text:
p = re.compile(r'(www[^ ]*|http://[^ ]*)')
text = p.sub(r'<a href="http://\1" rel="nofollow">\1</a>',ad.text.replace('http://',''))
else:
text = None
self.response.out.write("Message sent<br>")
path = os.path.join(os.path.dirname(__file__), 'market', 'market_ad_detail.html')
self.response.out.write(template.render(path, {'user_url':users.create_logout_url(self.request.uri) if users.get_current_user() else users.create_login_url(self.request.uri),
'user':users.get_current_user(), 'ad.user':ad.user,'count':count, 'ad':ad, 'matched_images': matched_images,}))
[UnicodeEncodeError:'ascii'編解碼器無法編碼字符u'\ xa3']的可能重複(http://stackoverflow.com/questions/3588083/unicodeencodeerror-ascii-codec-cant-encode-character-u -xa3) – hop 2011-03-05 16:58:02
如果您在SO上搜索該錯誤,您將獲得頁面和頁面以及頁面和頁面以及頁面和問題和答案頁面 – hop 2011-03-05 16:58:45
感謝信息工作者 – 2011-03-05 17:10:43