Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python3wsgi-json响应_Python_Json_Response_Uwsgi_Wsgi - Fatal编程技术网

python3wsgi-json响应

python3wsgi-json响应,python,json,response,uwsgi,wsgi,Python,Json,Response,Uwsgi,Wsgi,我使用uwsgi为我的web内容提供服务,它在普通html页面上运行良好: return [b'<html><head></head><body>Hello, world!</body></html>'] Web服务器不返回任何内容…没有错误,只是响应正文为空。。。有人能解释为什么吗 谢谢和问候 如果这是您的完整代码,那么您忘记导入json库了 test = json.dumps(['foo', {'bar': ('baz

我使用
uwsgi
为我的web内容提供服务,它在普通html页面上运行良好:

return [b'<html><head></head><body>Hello, world!</body></html>']
Web服务器不返回任何内容…没有错误,只是响应正文为空。。。有人能解释为什么吗


谢谢和问候

如果这是您的完整代码,那么您忘记导入json库了

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]
import json
def application(environ, start_response):
    headers = [('Content-Type', 'application/json')]
    start_response('200 OK', headers)
    test = json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
    test1 = test.encode('utf-8')      
    return [test1]

如果这是您的完整代码,那么您忘了导入json库

import json
def application(environ, start_response):
    headers = [('Content-Type', 'application/json')]
    start_response('200 OK', headers)
    test = json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
    test1 = test.encode('utf-8')      
    return [test1]
对于测试,请使用此

转储({“newdata”:“test”})

用于测试的


json.dumps({“newdata”:“test”})

您能添加更多信息吗,例如回溯?嘿,我更新了我的问题并添加了完整的代码。没有错误,只是一个空的响应正文..我是第一个出现此问题的人吗?请您添加更多信息,例如回溯?嘿,我更新了我的问题并添加了完整的代码。没有错误,只是一个空的响应体..我是第一个出现这个问题的人吗?