0

在 POST 时在 Heroku 上使用 Filebrowser 和 S3 出现 500 错误。我已经添加了堆栈跟踪和模型信息 :) 这可能是 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)

我不知道如何开始调试这个。有人对此有见解吗?谢谢!

4

1 回答 1

0

这个忘记回答了。。。

Filebrowser 与 django-storages 不兼容。

谢谢@solarissmoke

于 2016-07-17T04:09:49.280 回答