我正在编写一些简单的脚本来将文本与 rot13 相互转换。所以在适当的类里面我有这个:
def post(self):
dict = string.maketrans("ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz", "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
code = self.request.get("text")
code = string.translate(code, dict)
它可以很好地获取参数“文本”,但在 .translate 中它会因内部服务器错误而爆炸:
File "<mypath>\main.py", line 46, in post
code = string.translate(code, dict)
File "C:\Python27\lib\string.py", line 498, in translate
return s.translate(table + s[:0])
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 128: ordinal not in range(128)
我的代码有什么问题?