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

download functions on .txt files #121

Open
deroskarmodulo opened this issue Jul 30, 2022 · 1 comment
Open

download functions on .txt files #121

deroskarmodulo opened this issue Jul 30, 2022 · 1 comment

Comments

@deroskarmodulo
Copy link

When trying to download a .txt file from my cloud I got the error KeyError: 'content-length'. Actually it worked with .txt files with less than exactly 256 characters. Other file types (such as .png, .jpeg, .mp3, .csv) worked just fine. It did not matter of which format the local file was (so even that client.download_file('/publish/_testing/test', 'tmp/test.txt') worked.

Code: client.download_file('/publish/_testing/test.txt', 'tmp/_local_test.txt'))
test.txt: testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
Error:

  File "my_file.py", 
line 36, in <module>
    print(client.download_file('/publish/_testing/test.txt', 'tmp/test.txt'))
  File "webdav3\client.py", line 67, in _wrapper
    res = fn(self, *args, **kw)
  File "webdav3\client.py", line 458, in download_file
    total = int(response.headers['content-length'])
  File "requests\structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'content-length'
@deroskarmodulo
Copy link
Author

The problem is that in the download_file function in client.py the execute_request function delivers a header without a 'content-length' entry for .txt-files with more than 255 characters. To prevent the script from failing due to this error, you could add an exception like this:

        with open(local_path, 'wb') as local_file:
            response = self.execute_request('download', urn.quote())
            try:
                total = int(response.headers['content-length'])
            except:
                total = None
            current = 0

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

No branches or pull requests

1 participant