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

Error on performing file operations #48

Open
arwankhoiruddin opened this issue Sep 21, 2016 · 4 comments
Open

Error on performing file operations #48

arwankhoiruddin opened this issue Sep 21, 2016 · 4 comments

Comments

@arwankhoiruddin
Copy link

arwankhoiruddin commented Sep 21, 2016

Hi,

I exactly followed your guide to connect to my webdav server. Here is my code

import easywebdav

webdav = easywebdav.connect('http://my-server.com/remote.php/webdav/',username='my-username',password='my-password')

I did not have problem so far.

However, when I add another line of code, for example webdav.ls() or webdav.mkdir('adirectory'), it gives me the following error.

Traceback (most recent call last):
  File "/Users/arwankhoiruddin/Documents/sss/coba.py", line 6, in <module>
    webdav.mkdir("easywebdav")
  File "/Users/arwankhoiruddin/scram/lib/python2.7/site-packages/easywebdav/client.py", line 123, in mkdir
    self._send('MKCOL', path, expected_codes)
  File "/Users/arwankhoiruddin/sss/lib/python2.7/site-packages/easywebdav/client.py", line 97, in _send
    response = self.session.request(method, url, allow_redirects=False, **kwargs)
  File "/Users/arwankhoiruddin/sss/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/arwankhoiruddin/sss/lib/python2.7/site-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/Users/arwankhoiruddin/sss/lib/python2.7/site-packages/requests/adapters.py", line 487, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //my-server/remote.php/webdav/:80/easywebdav (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x10ebaac90>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

Please suggest. Thanks

@ghost
Copy link

ghost commented Aug 8, 2017

I see that you were on owncloud. I just tested this out on nextcloud's demo server with success:

>>> webdav = easywebdav.connect('demo.nextcloud.com', username='admin', password='admin', protocol='https', port=443, path='/xee8uy5p/remote.php/webdav/')
>>> webdav.delete('Nextcloud.mp4')

Hope this helps a year later ;)

@ghost
Copy link

ghost commented Aug 8, 2017

Despite the above, I'm having difficulties with it on my own nextcloud server. I'm going to guess it has something to do with my nginx configuration... but curl works just fine.

>>> webdav.ls()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/easywebdav/client.py", line 184, in ls
    return [elem2file(elem) for elem in tree.findall('{DAV:}response')]
  File "/usr/lib/python3.6/site-packages/easywebdav/client.py", line 184, in <listcomp>
    return [elem2file(elem) for elem in tree.findall('{DAV:}response')]
  File "/usr/lib/python3.6/site-packages/easywebdav/client.py", line 40, in elem2file
    int(prop(elem, 'getcontentlength', 0)),
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

That's if I specify path='blah'. If I just append the path to the host (.e.g. myserver.com/remote.php/webdav/), then I get:

>>> webdav.ls()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/easywebdav/client.py", line 176, in ls
    response = self._send('PROPFIND', remote_path, (207, 301), headers=headers)
  File "/usr/lib/python3.6/site-packages/easywebdav/client.py", line 100, in _send
    raise OperationFailed(method, path, expected_code, response.status_code)
easywebdav.client.OperationFailed: Failed to list directory ".".
  Operation     :  PROPFIND .
  Expected code :  207 Multi-Status, 301 Moved Permanently
  Actual code   :  404 Not Found

@deidyomega
Copy link

deidyomega commented Feb 17, 2019

Hey All!

Both of you are correct.

webdav = easywebdav.connect(
    'demo.nextcloud.com',
    username='admin',
    password='admin',
    protocol='https',
    port=443,
    path='/eeb3giep/remote.php/webdav/')
webdav.delete('Nextcloud.mp4') # delete works
webdav.ls() # ls --> results in errors @ghost reported

My solution is --> go into client.py and replace elem2file with:

def elem2file(elem):
    try:
        return File(
            prop(elem, 'href'),
            int(prop(elem, 'getcontentlength', 0)),
            prop(elem, 'getlastmodified', ''),
            prop(elem, 'creationdate', ''),
            prop(elem, 'getcontenttype', ''),
        )
    except:
        return File(
            prop(elem, 'href'),
            0,
            prop(elem, 'getlastmodified', ''),
            prop(elem, 'creationdate', ''),
            prop(elem, 'getcontenttype', ''),
        )

@KaratekHD
Copy link

try:
return File(
prop(elem, 'href'),
int(prop(elem, 'getcontentlength', 0)),
prop(elem, 'getlastmodified', ''),
prop(elem, 'creationdate', ''),
prop(elem, 'getcontenttype', ''),
)
except:
return File(
prop(elem, 'href'),
0,
prop(elem, 'getlastmodified', ''),
prop(elem, 'creationdate', ''),
prop(elem, 'getcontenttype', ''),
)

This works for me too.

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

3 participants