Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using Dropbox 8.1 MetaData is not subscriptable #396

Closed
riccardodivirgilio opened this issue Sep 26, 2017 · 8 comments
Closed

using Dropbox 8.1 MetaData is not subscriptable #396

riccardodivirgilio opened this issue Sep 26, 2017 · 8 comments
Labels

Comments

@riccardodivirgilio
Copy link

for entry in metadata['contents']:

using python3.5 and dropbox 8.1 I have got the following error:

  File "/home/server/env/lib/python3.5/site-packages/storages/backends/dropbox.py", line 79, in listdir
    for entry in metadata['contents']:
TypeError: 'FolderMetadata' object is not subscriptable

if I open the source code of dropbox I can see that the class MetaData is not defining a getitem method which is why this code is failing...

thanks and good job with this package

@riccardodivirgilio
Copy link
Author

what version of dropbox is supported from this code? thanks

@danni
Copy link

danni commented Oct 4, 2017

I tried this with Dropbox 8.0.0, which is what's in the tests. I suspect this may actually be related to Python 3.

@patroqueeet
Copy link

patroqueeet commented Nov 14, 2017

I ran in the same issue with python 2.7:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/utils.py", line 111, in wrapper
    func(*args, **kwargs)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/management/commands/dbbackup.py", line 63, in handle
    self._cleanup_old_backups(database=database_key)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/management/commands/_base.py", line 132, in _cleanup_old_backups
    servername=servername)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/storage.py", line 237, in clean_old_backups
    servername=servername)
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/storage.py", line 123, in list_backups
    files = [f for f in self.list_directory() if utils.filename_to_datestring(f)]
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/dbbackup/storage.py", line 78, in list_directory
    return self.storage.listdir(path)[1]
  File "/home/darg/darg/.ve/local/lib/python2.7/site-packages/storages/backends/dropbox.py", line 141, in listdir
    for entry in metadata['contents']:
TypeError: 'FolderMetadata' object has no attribute '__getitem__'

@danni
Copy link

danni commented Nov 14, 2017

Yep, what I learned is that the API had completed changed, and this was being masked in the tests by the mocks.

#402 contains the fix.

@patroqueeet
Copy link

@danni how did you fix that?

@patroqueeet
Copy link

patroqueeet commented Nov 14, 2017

fixed this in backends/dropbox.py with replacing listdir() with

    def listdir(self, path):
        directories, files = [], []
        full_path = self._full_path(path)
        metadata = self.client.files_get_metadata(full_path)
        for entry in self.client.files_list_folder(full_path).entries:
            entry.path_lower = entry.path_lower.replace(full_path, '', 1)
            entry.path_lower = entry.path_lower.replace('/', '', 1)
            if isinstance(entry, FolderMetadata):
                directories.append(entry.path_lower)
            else:
                files.append(entry.path_lower)
        return directories, files

sorry for not sending a PR, but I'm under heavy fire here and don't want to promise something I can't deliver.

@patroqueeet
Copy link

ah! stupid me. just now saw the PR from @danni . SRY! good job!

@jschneier
Copy link
Owner

Fixed by #724.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants