【发布时间】:2011-11-19 09:11:14
【问题描述】:
在制作我的 App Engine 应用时,我突然遇到了一个错误,该错误会显示每两个请求:
run_wsgi_app(application)
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/util.py", line 98, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/util.py", line 118, in run_bare_wsgi_app
for data in result:
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/appstats/recording.py", line 897, in appstats_wsgi_wrapper
result = app(environ, appstats_start_response)
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 717, in __call__
handler.handle_exception(e, self.__debug)
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 463, in handle_exception
self.error(500)
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 436, in error
self.response.clear()
File "/home/ubuntu/Programs/google/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 288, in clear
self.out.seek(0)
File "/usr/lib/python2.7/StringIO.py", line 106, in seek
self.buf += ''.join(self.buflist)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 208: ordinal not in range(128)
我真的不知道这可能在哪里,它只在我使用特定函数时发生,但不可能跟踪我拥有的所有字符串。
这个字节可能是' " [ ] 等字符,但仅限于另一种语言
我怎样才能找到这个字节以及可能的其他字节?
我在 ubuntu 11.04 中使用 python 2.7 运行 GAE
谢谢。
*更新*
这是我最终使用的代码: 从编解码器导入 BOM_UTF8 从操作系统导入列表目录,路径 p = "路径"
def loopPath(p, times=0):
for fname in listdir(p):
filePath = path.join(p, fname)
if path.isdir(filePath):
return loopPath(filePath, times+1)
if fname.split('.', 1)[1] != 'py': continue
f = open(filePath, 'r')
ln = 0
for line in f:
#print line[:3] == BOM_UTF8
if not ln and line[:3] == BOM_UTF8:
line = line[4:]
col = 0
for c in list(line):
if ord(c) > 128:
raise Exception('Found "'+line[c]+'" line %d column %d in %s' % (ln+1, col, filePath))
col += 1
ln += 1
f.close()
loopPath(p)
【问题讨论】:
-
您是否尝试过在缓冲区的位置
208处查看字节'\0xd7',正如错误明显指出的那样? -
该缓冲区是 StringIO 的一个内部变量,它在 GAE 的代码中非常深入。并且缓冲区不会告诉我它在我的代码中的确切位置,只有很多文本......