내 웹 응용 프로그램은 이전에 아주 잘 실행되었지만 며칠 전에 문제가 발생했습니다. 이제 웹 응용 프로그램을 시작할 수 있습니다. 로컬 (127.0.0.1)에서 사이트 또는 원격 (192.168.xxx.xxx)가 (만 단순히 홈페이지, 마우스 및 키보드 입력 없음을 엽니 다),이 같은 웹 애플리케이션 crashs :UnicodeDecodeError : 'utf8'코덱으로 5 바이트의 0xcb 바이트를 디코딩 할 수 없습니다. 연속 연속 바이트가 유효하지 않습니다.
Traceback (most recent call last):
File "/path/to/project/web/application.py", line 242, in process
return self.handle()
File "/path/to/project/web/application.py", line 233, in handle
return self._delegate(fn, self.fvars, args)
File "/path/to/project/web/application.py", line 415, in _delegate
return handle_class(cls)
File "/path/to/project/web/application.py", line 390, in handle_class
return tocall(*args)
File "./my_web_app.py", line 40, in GET
simplejson.dumps(manus))
File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 286, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 226, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 296, in iterencode
return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 5: invalid continuation byte
192.168.xxx.xxx:2131 - - [27/Nov/2013 16:51:09] "HTTP/1.1 GET /" - 500 Internal Server Error
192.168.xxx.xxx:2131 - - [27/Nov/2013 16:51:09] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
192.168.xxx.xxx:2131 - - [27/Nov/2013 16:51:09] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
을하고 내가 거기 같아요 내 코드가 내 컴퓨터에서 잘 실행되기 때문에 오류가 서버에서 실행될 때만 나타납니다. "web"디렉토리는 "web.py-0.34/web"에 대한 링크이며 내 코드가 아닙니다.
내 코드는 간단하다 :
urls = (
'/', 'find_alternate',
'/find_alternates', 'find_alternate',
'/show_detail/(.+)', 'show_detail'
)
app = web.application(urls, globals())
class find_alternate:
def GET(self):
brands = [b.brandName for b in Brand.q.all()]
brands.sort()
manus = [oe.brandName for oe in OeNumber.q.group_by(OeNumber.brandName)]
manus.sort()
return render.find_alternates_main(simplejson.dumps(brands), simplejson.dumps(manus))
"""
some more functions, but not relevant
"""
render = web.template.render('/path/to/templates/')
web.template.Template.globals['str'] = str
if __name__ == "__main__":
app.run()
이 테이블 만들기의 나 : jsonsimple 그것을 구문 분석 할 수 있도록 UTF-8 유니 코드 문자 Ë을 변환 HWO
CREATE TABLE `brand` (
`brandNo` int(11) NOT NULL,
`brandName` varchar(64) DEFAULT NULL,
PRIMARY KEY (`brandNo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
내 문제는 지금이다. 위키에서 나는 발견이 :
Unicode: U+00CB
UTF-8: C3(hex) 8B(hex)
나는 soluted 방법 :
collation-server = utf8_unicode_ci
init_connect='SET NAMES utf8'
character-set-server = utf8
skip-character-set-client-handshake
변환 된 데이터베이스를 UTF-8로 :
ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
"나는 거기에 뭔가 잘못되었다고 생각하지 않습니다."정말로 충분하지 않습니다. 중요한 코드를 게시하십시오. – jazzpi
분명히, 코드 나 웹 서버 구성 또는 액세스하는 방식에 문제가 있습니다. 그리고 세 가지에 관한 정보를 우리에게주지 않았기 때문에 아무도 당신을 도울 방법이 없습니다. 어떤 이유에서든 UTF-8이 아닌 데이터 (예 : Latin-1 또는 Windows CP1252)를 전송한다는 일반적인 힌트를 제공하는 경우를 제외하고 코드 또는 web.py가 UTF-8로 해석하려고 시도하고 있습니다 이유. [Unicode HOWTO] (http://docs.python.org/2/howto/unicode.html)를 읽지 않았다면, 지금은 좋은 시간 일 것입니다. – abarnert
sry, 나는 내 말을 끝내지 않았고 missclicked "post" – Cricket