在Django中播放上传的音频文件时出错

时间:2019-03-17 06:27:50

标签: python django

这是发生错误的追溯

[17/Mar/2019 11:15:26] "GET /media/songs/Three_Days_Grace_-_Break.mp3 

HTTP/1.1" 200 4579328
Traceback (most recent call last):
  File "C:\Python36\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 279, in write
    self._write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "C:\Python36\lib\socketserver.py", line 800, in write
    self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
[17/Mar/2019 11:15:26] "GET /media/songs/Three_Days_Grace_-_Break.mp3 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54509)
Traceback (most recent call last):
  File "C:\Python36\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 279, in write
    self._write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "C:\Python36\lib\socketserver.py", line 800, in write
    self._sock.sendall(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:\Python36\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "D:\Django Projects\Virtual Envs\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error
    super().handle_error()
  File "C:\Python36\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Python36\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Python36\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:\Python36\lib\socketserver.py", line 651, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python36\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python36\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "D:\Django Projects\Virtual Envs\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle
    self.handle_one_request()
  File "D:\Django Projects\Virtual Envs\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
    handler.run(self.server.get_app())
  File "C:\Python36\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "D:\Django Projects\Virtual Envs\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
    super().close()
  File "C:\Python36\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

请注意,我仍然可以在模板视图中播放音频文件,但是无法找到此文件的特定持续时间。关于为什么会发生这种情况的任何提示吗?

这是我的models.py代码:

class Song(models.Model):
    song_name = models.CharField(max_length=100)
    album_name = models.ForeignKey(Album, on_delete=models.CASCADE)
    song_file = models.FileField(upload_to='songs/', null=True,
                                 validators=[validate_song_extension])

    def get_absolute_url(self):
        return reverse('music:song-detail', kwargs={'pk': self.pk})

    def __str__(self):
        return self.song_name

我正在使用一个简单的CreateView来接受此Song模型的新条目,而没有form_valid()方法,这可能是导致我收到此错误的原因吗?

0 个答案:

没有答案