Heroku + S3上的Django-Filebrowser 500错误

时间:2016-07-01 05:26:39

标签: django heroku django-storage django-filebrowser

使用Filebrowser获取500错误&在POST上Heroku上的S3。我添加了堆栈跟踪和模型信息:)这是一个S3问题或与Filebrowser有关吗?

来自终端的堆栈跟踪:

[01/Jul/2016 05:19:10] "GET /admin/filebrowser/browse/?pop=1&dir=300x250/160x600 HTTP/1.1" 500 76295
Internal Server Error: /admin/filebrowser/browse/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/scott/Sites/banner_preview_tool_venv/banner_preview_tool/filebrowser/decorators.py", line 35, in decorator
if get_path('', site=site) is None:
File "/Users/scott/Sites/banner_preview_tool_venv/banner_preview_tool/filebrowser/decorators.py", line 18, in get_path
if site.storage.isdir(converted_path):
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 205, in inner
return func(self._wrapped, *args)
AttributeError: 'MediaStorage' object has no attribute 'isdir'
2016-07-01 05:19:14,947 ERROR Internal Server Error: /admin/filebrowser/browse/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/scott/Sites/banner_preview_tool_venv/banner_preview_tool/filebrowser/decorators.py", line 35, in decorator
if get_path('', site=site) is None:
File "/Users/scott/Sites/banner_preview_tool_venv/banner_preview_tool/filebrowser/decorators.py", line 18, in get_path
if site.storage.isdir(converted_path):
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 205, in inner
return func(self._wrapped, *args)
AttributeError: 'MediaStorage' object has no attribute 'isdir'

以下是模型:

file = FileBrowseField("HTML or ZIP File", max_length=256, blank=True, null=True, extensions=[".zip",".html"], help_text="Upload an html file or a zip file of banners")

def save(self, *args, **kwargs):
    self.slug = slugify(self.name)

    super(BannerCode, self).save(*args, **kwargs)

def __unicode__(self):
    return self.name

def post_upload_callback(sender, **kwargs):
    if kwargs['file'].extension == ".zip":
        path = kwargs['path'] 
        thefile = kwargs['file'] 

        # Convert file and dir into absolute paths
        fullpath = os.path.join(settings.MEDIA_ROOT, '' + thefile.path)
        dirname = os.path.dirname(fullpath)

        # Get a real Python file handle on the uploaded file
        fullpathhandle = open(fullpath, 'r') 

        # Unzip the file, creating subdirectories as needed
        zfobj = zipfile.ZipFile(fullpathhandle)
        for name in zfobj.namelist():
            if name.endswith('/'):
                try: # Don't try to create a directory if exists
                    os.mkdir(os.path.join(dirname, name))
                except:
                    pass
            else:
                outfile = open(os.path.join(dirname, name), 'wb')
                outfile.write(zfobj.read(name))
                outfile.close()

        # Now try and delete the uploaded .zip file and the  __MACOSX dir if they exist.
        try:
            os.remove(fullpath)
        except:
            pass

        try:
            osxjunk = os.path.join(dirname,'__MACOSX')
            shutil.rmtree(osxjunk)
        except:
            pass                

# Signal provided by FileBrowser on every successful upload. 
filebrowser_post_upload.connect(post_upload_callback)

我不知道如何开始调试这个。任何人都有这方面的见解? THX!

1 个答案:

答案 0 :(得分:0)

忘了回答这个......

Filebrowser与django-storages不兼容。

谢谢@solarissmoke