【发布时间】:2016-09-11 07:16:58
【问题描述】:
访问帖子页面时出现奇怪的错误。我制作 Web 应用程序,您可以在其中发布图像和视频。使用图像它可以正常工作,但是当我发布视频并转到其页面时,服务器会给我以下输出:
Traceback (most recent call last):
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 453, in _write
self.stdout.write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 593, in write
return self._sock.send(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
[15/May/2016 13:50:09] "GET /media/uploads/Big_Buck_Bunny_Final.mp4 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 23943)
[15/May/2016 13:50:09] "GET /static/image/video-poster.jpg HTTP/1.1" 304 0
Traceback (most recent call last):
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 453, in _write
self.stdout.write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 593, in write
return self._sock.send(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\servers\basehttp.py", line 92, in handle_error
super(ServerHandler, self).handle_error()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 628, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\servers\basehttp.py", line 99, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\socketserver.py", line 684, in __init__
self.handle()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\servers\basehttp.py", line 179, in handle
handler.run(self.server.get_app())
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\Slavko\AppData\Local\Programs\Python\Python35-32\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
图像和视频的代码是相同的,这就是我不明白这一点的原因。 这是我的视图功能,当您访问帖子页面时使用:
def post_info(request, pk):
form = CommentForm(request.POST or None)
post = get_object_or_404(Post, pk=pk)
same_author_posts = Post.objects.filter(author=post.author)
if request.method == 'POST':
if form.is_valid():
instance = form.save(commit=False)
instance.author = request.user
instance.post = post
instance.save()
form = CommentForm()
messages.success(request, 'Comment is approved!')
return HttpResponseRedirect('/post/%s/'%(pk))
else:
messages.error(request, 'Comment is not valid!')
return HttpResponseRedirect('/post/%s/'%(pk))
context = {
'form': form,
'post': post,
'same_author_posts': same_author_posts,
}
return render(request, 'post/post_info.html', context)
可能它在响应中有一些带有状态码的东西,但是为什么它在加载图像时不显示它以及如何修复它?
【问题讨论】:
-
您是否检查了您存储文件的目录的权限?
-
是的,一切正常。我注意到,当例如 127.0.0.1:8000 更改为 127.0.0.1:9000 时,有时会引发相同的错误。但是我还是能理解为什么我去post_info.html看图片时他没有显示,只有视频输出错误。
-
你发现了什么? ): 我有同样的错误
-
我正在做一些学校项目。我发现当文件太大时会发生该错误。我不知道这是为什么。例如,我制作网站,您可以在其中发布图像或视频以及更多内容。问题是浏览器渲染视频或大图像时,所以我压缩视频并且它工作正常。但是当我在笔记本电脑上运行相同的视频(比我的 PC 慢)时,它会显示相同的错误。所以,我认为这是 Django 开发服务器的一些错误(在我的情况下)。该错误不会停止网站或其他任何内容,它仍然可以正常工作。尝试压缩文件,您将不会再看到错误。
-
另外,我发现服务器打开了新连接,但不要关闭旧连接。正如我在我的 PC 上所说的,它工作正常,在笔记本电脑上我需要再压缩一次。它与文件的大小和计算机的速度有一些联系......也可能发生你的一些功能,,返回无”(我在某处读过)。