[英]Simple HTTP response: why does this work with Python2 but not with Python3
使用以下代碼,運行:
uwsgi --socket myapp.sock --plugins /usr/lib/uwsgi/plugins/python_plugin.so \
--module wsgi --chmod-socket=664
我不明白為什么在使用/usr/lib/uwsgi/plugins/python_plugin.so時為什么會給我卷曲的GET和POST值,但在使用/ usr / lib / uwsgi / plugins / python 3 _plugin.so時卻不能。
我正在使用curl,如下所示: curl -v --form 'file=@testfile;filename=newfilename' --form 'q=c' localhost?q=x
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
try:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = environ.get('wsgi.input', b'').read(request_body_size).decode('utf-8')
get_values = environ.get('QUERY_STRING', '')
return ["Hello There!\n\n" + request_body + get_values]
我在Python3中添加了解碼('utf-8')以將字節轉換為字符串。 使用Python2時,我忽略了這一點。
return ["Hello There!\n\n" + request_body + get_values]
變成:
return [("Hello There!\n\n" + request_body + get_values).encode('utf-8')]
使它工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.