gpt4 book ai didi

python - 处理 WSGI 脚本时发生异常 - IOError : failed to write data

转载 作者:IT老高 更新时间:2023-10-28 13:27:14 25 4
gpt4 key购买 nike

我正在尝试将图像保存在服务器端。我将它作为 base64 字符串接收,因此我先对其进行解码,然后将其保存在数据库中。但是这失败了,所以我检查了服务器错误日志,我发现下列的错误日志

    [Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] mod_wsgi (pid=4952): Exception occurred processing WSGI script '/root/AR_BROWSER/example/wsgi.py'.
[Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] IOError: failed to write data

我检查了 wsgi.py

import os
import sys

path = '/root/AR_BROWSER/example'

sys.path.append('/root/AR_BROWSER/example')
sys.path.append('/root/AR_BROWSER')
sys.path.append('/root/AR_BROWSER/example/app')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

但我找不到错误的地方。知道这个问题的原因是什么吗?!负责保存图片的代码

 @csrf_exempt    
def create_app(request):
appName = request.POST['name']
user = request.POST['userID']
c = request.POST['category']
i = request.POST['image']
imgdata = base64.b64decode(i)
t = datetime.now()
filename = t.strftime('test.jpg')
with open(filename, 'w') as f:
f.write(imgdata)
f.close()
u=App_User.objects.get(id=user)
apps = App.objects.create(name = appName, category=c, user_id = u.id, app_logo=File(filename))
apps.save()

return HttpResponse("You created %s." % apps.name)

最佳答案

来自 mod_wsgi 的没有回溯的消息通常意味着 HTTP 客户端在 mod_wsgi 将所有响应数据写回之前关闭了连接。

关于python - 处理 WSGI 脚本时发生异常 - IOError : failed to write data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16670417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com