一、报错描述
????最近在做一个Django博客的功能,通过admin界面上传图片,浏览器提示上传文件时一直发生HTTP错误(错误代码:500),这个问题困扰了我很久,修改settings.py和urls.py都没有解决,最后发现可能是python版本实现的问题,通过修改源代码最终上传成功了。 ????报错信息如下所示:
Traceback (most recent call last):
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/ckeditor_uploader/views.py", line 114, in post
filepath = get_upload_filename(uploaded_file.name, request)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/ckeditor_uploader/views.py", line 83, in get_upload_filename
return storage.get_available_name(os.path.join(upload_path, upload_name))
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/files/storage.py", line 75, in get_available_name
while self.exists(name) or (max_length and len(name) > max_length):
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/files/storage.py", line 310, in exists
return os.path.exists(self.path(name))
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/files/storage.py", line 323, in path
return safe_join(self.location, name)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/zc/PycharmProjects/Django/mysite_env/lib/python3.8/site-packages/django/core/files/storage.py", line 207, in location
return os.path.abspath(self.base_location)
File "/Users/zc/opt/anaconda3/lib/python3.8/posixpath.py", line 375, in abspath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not tuple
二、解决方法
????我的解决方法是找到报错信息中提示的源文件posixpath.py,按照提示将tuple进行解包,修改两个地方就可以(如果还不行可以多尝试几个地方): ????1. 找到abspath函数,如果path是tuple,进行解包 ????2. 找到join函数,如果a是tuple,进行解包 ????希望能帮助到有需要的人。
|