Python 3 wsgi - json 响应

标签 python json response uwsgi wsgi

我使用 uwsgi 来提供我的 Web 内容,它在处理常见的 html 页面时效果很好:

return [b'<html><head></head><body>Hello, world!</body></html>']

但是当我想返回json时:

headers = [('content-type', 'application/json')]
test = json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
test1 = bytearray(test, 'utf8')

start_response('200 OK', headers)
return [test1]

网络服务器没有返回任何内容...没有错误,只是空响应正文...有人可以解释我为什么吗?

感谢和问候!

最佳答案

test = json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])    
test1 = bytes(test, 'utf-8') # or test.encode('utf-8')
start_response('200 OK', headers)
return [test1]

关于Python 3 wsgi - json 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43619492/

相关文章:

javascript - 如何根据定期获取的数据生成Chrome扩展程序的弹出正文?

PHP json_encode 将行作为对象而不是数组返回

android - 为什么 WebResourceResponse 在 shouldInterceptRequest() 中返回 null?

python - 是否可以强制 SymPy 计算积分,或者告诉我为什么它无法计算积分?

python - 如何查找要在其他文件中导入的类的完整模块路径

python - 根据第一个子模型的属性对查询集进行排序,会返回重复的对象。 Django ,DRF

python - 如何确定某个库(例如 pypi.org 上的库)是否适合 Python 3

java - 使用 Jackson 将 GeoJSON 映射到 Java

c# - HttpResponse.End 与 HttpResponse.Close 与 HttpResponse.SuppressContent

r - 如何下载和/或提取 R 中响应对象内的 'raw' 二进制 zip 对象中存储的数据?