Python 如何配置uWsgi服务器以防止出现无法读取的Post错误?

Python 如何配置uWsgi服务器以防止出现无法读取的Post错误?,python,wsgi,uwsgi,Python,Wsgi,Uwsgi,这就是问题所在: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/six.py", line 535, in next return type(self).__next__(self) File "/app/.heroku/python/lib/python2.7/site-packages/django/http/multipartparser.py", line 344, in __next

这就是问题所在:

  File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/six.py", line 535, in next
    return type(self).__next__(self)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/http/multipartparser.py", line 344, in __next__
    output = next(self._producer)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/six.py", line 535, in next
    return type(self).__next__(self)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/http/multipartparser.py", line 406, in __next__
    data = self.flo.read(self.chunk_size)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/http/request.py", line 267, in read
    six.reraise(UnreadablePostError, UnreadablePostError(*e.args), sys.exc_info()[2])
  File "/app/.heroku/python/lib/python2.7/site-packages/django/http/request.py", line 265, in read
    return self._stream.read(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 59, in read
    result = self.buffer + self._read_limited(size - len(self.buffer))
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 47, in _read_limited
    result = self.stream.read(size)
UnreadablePostError: error during read(65536) on wsgi.input
我当前的配置如下所示:

[uwsgi]
http-socket = :$(PORT)
master = true
processes = 4
die-on-term = true
module = app.wsgi:application
memory-report = true
chunked-input-limit = 25000000
chunked-input-timeout = 300
socket-timeout = 300
Python:2.7.x | uWsgi:2.0.10

更具体地说,当我在上传图像的同时同步处理图像时,就会出现这种情况。我知道,理想情况下,我必须用芹菜来做这件事,但由于业务需要,我无法做到这一点。所以需要配置超时,使其允许我接受一个大的图像文件,处理它,然后返回响应


对这个问题的任何解释都会非常有帮助。谢谢。

描述中引用的错误并非全貌;相关部分为该批次条目:

[uwsgi-body-read] Error reading 65536 bytes … message: Client closed connection uwsgi_response_write_body_do() TIMEOUT
引发此特定错误的原因是(很可能)客户端或它与uWSGI之间的某个对象中止了请求

造成这种情况的原因有很多:

  • 有问题的客户
  • 网络级过滤(或某些配置错误的防火墙)
  • uWSGI前面的服务器中存在错误/配置错误
最后一个问题包括在:

如果您计划将uWSGI置于代理/路由器之后,请确保它支持分块输入请求(或通常为原始HTTP请求)


要验证您的问题确实不在uWSGI中,请尝试通过托管uWSGI应用程序的服务器上的控制台上载该文件。直接点击HTTP端点,绕过nginx/haproxy和friends。

请发布您正在使用的uwsgi和python版本。您是否尝试在配置文件中设置
缓冲区大小=65536
?您能提供一个再现问题的最小示例吗?@NguyenSyThanhSon不,我没有尝试设置缓冲区大小。@Phillip对于大于7mb的图像,有时甚至是小于5MB的图像,会发生这种情况。