[컴][웹] 구글 앱 엔진 Google App engine UTF-8 문제 / StringType Assertion 문제

Google App Engine with python 2.7 / error StringType error
 

Update 2012.09.30

결국 framework 를 Django 로 교체했다. 잘 동작한다.

------------------------------------------------------------------
도저히 방법을 못 찾고 있다. 문제는 Web Server Gateway Interface(WSGI) framework 에서 StringType 으로 type 검사를 하기 때문으로 보인다. 영어만 넘기는 것은 문제가 없다. 하지만 "한글"이 들어갈 때 Assertion 이 발생한다.

문제의 코드는 아래와 같다. 아래코드에서 self.response.out.write() 이 "contents" 의 type 이
<class 'google.appengine._internal.django.utils.safestring.SafeUnicode'>
인데, 이것에 대해 StringType 이 아니라는 이유로 에러를 발생시킨다.
.py code

v2 = ['테스트','테스트2']
testval = {'melon':['m1' ,'m2','m3'],
'billboard':v2
}
contents = template.render("templates/template_muchart.html",
{'chartdata': testval,
'chartname': chartNameList
})
if type(contents) != str :
logging.error('error')
logging.info(type(contents))
self.response.out.write(contents)


Error message

2012-09-20 17:12:48.307 Traceback (most recent call last):
E 2012-09-20 17:12:48.307 File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 86, in run
E 2012-09-20 17:12:48.307 self.finish_response()
E 2012-09-20 17:12:48.307 File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
E 2012-09-20 17:12:48.308 self.write(data)
E 2012-09-20 17:12:48.308 File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 202, in write
E 2012-09-20 17:12:48.308 assert type(data) is StringType,"write() argument must be string"
E 2012-09-20 17:12:48.308 AssertionError: write() argument must be string

아래 2개의 글을 보면, 이것에 대해 수정한 부분들이 있는데, 문제는 이 수정부분을 google app engine 에 적용시킬 방법이 없다.
현상태에서 방법은
  1. webapp2 를 버리고 다른 WSGI 를 택하거나,
  2. StringType 으로 만들어주는 template library 를 사용해야 할 듯 하다.
아직 진행 중이지만, 좋은 방법이 떠오르지 않는다.

댓글 없음:

댓글 쓰기