求教基础问题 关于中文传参

2011-01-23 22:08:54 +08:00
 supersheep
1.当我通过需要接受get或post参数交给python脚本处理的时候。
如果发送的是中文数据
比如 "http://localhost:8081/myapp?key=内容"
就会发生500错误。
  
2.如果发送英文数据,如
"http://localhost:8081/myapp?key=value"
则没这个问题,可以通过以下方式输出。
  
class myHandler(webapp.RequestHandler)
def get(self):
   print self.request.get('key')
  
但是输出内容为:
value
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
这种格式。

我不需要后面的状态信息,该怎么办呢?

谢谢大家!
3888 次点击
所在节点    Google App Engine
3 条回复
darasion
2011-01-23 22:37:04 +08:00
0、这个节点好像是Google 而不是 Google App Engine。
1、正确的应该是 self.response.out.write(self.request.get('key').encode('utf-8'))
2、print 输出的都是“ raw data ”[1],所以会包含传给浏览器的所有内容(包括http协议头,数据内容等;不叫状态信息)。


[1]具体解释见:http://code.google.com/appengine/docs/python/runtime.html#Responses
“ App Engine collects all of the data the request handler script writes to the standard output stream, then waits for the script to exit. When the script exits, all of the output data is sent to the user.”
Hinc
2011-01-23 22:38:59 +08:00
中文,URL 之类的参数值都是要做编码处理的。
supersheep
2011-01-24 13:37:40 +08:00
各种羞愧。谢谢ls两位。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/7563

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX