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

标签 python django mongodb django-uploads

我正在尝试将图像保存在服务器端。我将它作为 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/

相关文章:

Python PYserial WxPython 线程

python - 使用Fast API接收图像,然后使用cv2处理它,然后将其返回

python - seaborn.barplot 会采用 matplotlib.pyplot 变量而不传递任何参数吗?

node.js - Mongoose 前或后保存钩子(Hook)用于更新关系?

node.js - Node.js 和 Mongoose 中的补丁请求方法

MongoDB 驱动程序无法连接到 MySQL 服务器

python - 从函数返回多个值的最佳方法是什么?

python - Django-admin.py 不工作(-bash :django-admin. py:找不到命令)

django - 使用 supervisord 运行 nginx/postgres - 需要吗?

python - 网址 http ://localhost:8000/admin/redirects to wrong page