Code Monkey home page Code Monkey logo

easywebdav's People

Contributors

amnong avatar ashleyhood avatar chadburrus avatar ciarang avatar glader avatar kartoch avatar killerx avatar tebeka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easywebdav's Issues

Running upload() on python 3 fails

Running upload() on python 3 leads to the error because basestring is no longer available in Python 3.

Stack trace:

def upload(self, local_path_or_fileobj, remote_path):
--> 153         if isinstance(local_path_or_fileobj, basestring):
    154             with open(local_path_or_fileobj, 'rb') as f:
    155                 self._upload(f, remote_path)

NameError: name 'basestring' is not defined

1.0.8

Hi. Please upload 1.0.8 version to pypi. Thanks.

please tag releases

it would be great if you could tag your releases, so they can be more easily tracked (e.g. for comparing whether the Debian packages are still up-to-date without having to parse code)

Updates/Maintenance in pypi

@amnong I unfortunately am unable to find a nice way of privately contacting you so I am raising this as an issue here.

Would you consider adding someone as a maintainer for this project on pypi, so new versions of this great package could be released. I believe it would be of big help to many python devs who have to deal with WebDav to be able to take full advantage of this library directly via pip, and not by having to manually cobble together a fork with all patches that they need.

If you would be willing to consider letting me become a maintainer of the package in pipy or have any questions feel free to drop an email to killerx (at) sess-on.net

shutil.copyfileobj(response.raw, f) doesn't work for me

Hi there,
Can I just start by saying that this is a very nice little module!
I am trying to download a file from a Sharepoint site and when I do so I end up with an empty file.
I looked in the code and tried using your original (i'm guessing) line: f.write(response.content) @line 126 of client.py which works just fine for me instead of the shutil.copyfileobj method call.
I can't figure out what is wrong, your code looks fine. Could it be something up on my end?
I am in business anyway but I just thought I would point this out.
Thanks!

Python3 adaptions

I did some small adaptions to solve issues in Python3. The prop method fired an exception when getcontentlength exists but return None
client.py.zip

SSL not supported due to arbitrary hardcodings

Subj says it all, and should give a hint for solution - if URL is going to be constructed from user input, then just let the user pass the URL instead:

-    def __init__(self, host, port=80, username=None, password=None):
-        self.baseurl = 'http://{}:{}'.format(host ,port)
+    def __init__(self, baseurl, username=None, password=None):
+        self.baseurl = baseurl

ls command does not work

I'm trying to ls a directory with latest version, but I have the following error message:

File "/home/kartoch/opt/python/pelican/src/easywebdav/easywebdav/client.py", line 174, in ls
  tree = xml.parse(StringIO(response.content))
TypeError: initial_value must be str or None, not bytes

mkdirs() fails on some webdav servers

A call to mkdirs('/some/folder/') will result in calling:

  1. self.mkdir('/some')
  2. self.mkdir('folder')

However some webdav (for example nginx) servers require a slash at the end of the path to folder:

  1. self.mkdir('/some/')
  2. self.mkdir('folder/')

RFC has no explicit requirement for a slash, but all the examples are given with it:
https://tools.ietf.org/html/rfc2518#page-33

So this is probably a good idea to add slashes in the end of path in mkdir calls.

Directory listing support

Note: Directory listing is not supported. I'll implement it upon request.

Here's the request ;-). The library is a fresh breath from the bloat/mess present in other py libraries, but without ls(), it's hard to just start playing with it.

Solution MacOS python3 basestring

Hi,

basestring is not defined in the client.py file if you use python3.
Workaround:
open client.py and add after line 14 the line: basestring = str
After editing it should look like the following lines.

12: else:
13: from http.client import responses as HTTP_CODES
14 : from urllib.parse import urlparse
15: basestring = str

HEAD returns a 301 for exists function when directory exists

I've the following error stack:

Traceback (most recent call last):
  File "/home/kartoch/Documents/works/web/www/tasks.py", line 56, in publish
    print(webdav.exists(remote_path))
  File "/home/kartoch/opt/python/pelican/src/easywebdav/easywebdav/client.py", line 178, in exists
    response = self._send('HEAD', remote_path, (200, 404))
  File "/home/kartoch/opt/python/pelican/src/easywebdav/easywebdav/client.py", line 98, in _send
    raise OperationFailed(method, path, expected_code, response.status_code)
easywebdav.client.OperationFailed: Failed to head "resources".
  Operation     :  HEAD resources
  Expected code :  200 OK, 404 Not Found
  Actual code   :  301 Moved Permanently

The problem seems that the webdav server is returning a 301 when method exists() check for existing directory, and easywebdav is expecting a 200 or 404.

Error on performing file operations

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

NameError: global name 'basestring' is not defined (python 3)

Hey there,
Nice work you have done, thanks!
I just came across an error while trying to download/upload files with my python3.3 install:

NameError: global name 'basestring' is not defined

After a quick web research, I found the solution mentioned here to work just fine.
I added the lines right after the import lines in client.py.

Requesting ls() with colon ':' in path

I get an error when i request ls() with colon in it

File "build/bdist.macosx-10.10-intel/egg/easywebdav/client.py", line 176, in ls
  File "build/bdist.macosx-10.10-intel/egg/easywebdav/client.py", line 100, in _send
easywebdav.client.OperationFailed: Failed to list directory "/router-autoscroll-master/examples/deprecated-iron-router-example/packages/okgrow:iron-router-autoscroll/".
  Operation     :  PROPFIND /router-autoscroll-master/examples/deprecated-iron-router-example/packages/okgrow:iron-router-autoscroll/
  Expected code :  207 UNKNOWN, 301 Moved Permanently
  Actual code   :  404 Not Found

Is there any encoding i need to do for the path before using ls?

ls() fails on Nextcloud server

When I run the ls() command with a connection to a Nextcloud server parts of my stacktrace look like this:

  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'

It seems as if not content length for directories is provided. I solved the issue by changing the return statement of prop in client.py to return default if child is None or child.text is None else child.text.
I'll be submitting a pull request for this shortly.

Not support unicode path

eg: webdav.ls('/软件')

Traceback (most recent call last):
  File "webdavclient.py", line 15, in <module>
    print webdav.ls(u'./软件')
  File "/usr/local/lib/python2.7/dist-packages/easywebdav/client.py", line 176, in ls
    response = self._send('PROPFIND', remote_path, (207, 301), headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/easywebdav/client.py", line 96, in _send
    url = self._get_url(path)
  File "/usr/local/lib/python2.7/dist-packages/easywebdav/client.py", line 104, in _get_url
    path = str(path).strip()
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-3: ordinal not in range(128)

Call to download() results in zero sized files

Hello!

When using the latest version of easywebdav,

easywebdav 1.0.7
requests 1.1.0
webdav server: mod_dav, apache2
ubuntu 12.10

I have a problem using downloading files. When doing a download (by calling the download() method), the file is created on the local machine with the correct name, but the file is empty (zero size).

When looking at the code I can see response.raw is used as an input to shutil.copyfileobj(). However, I think that the documentation for requests states that 'stream=True' must be used in the call to session.request for .raw to be valid (http://docs.python-requests.org/en/latest/api/):

"raw = None
File-like object representation of response (for advanced usage).
Requires that 'stream=True' on the request."

I have tried setting stream=True (line 77 in client.py). and the received file then contains data! However, when looking at the header I can see that my webdav server gzip'ing the files, so the files downloaded have to be unszipped.

*** client-new.py   2013-02-20 08:27:29.941967542 +0100
--- client-org.py   2013-02-18 14:17:59.114443000 +0100
***************
*** 76,78 ****
          url = self._get_url(path)
!         response = self.session.request(method, url, allow_redirects=False, stream=True, **kwargs)
          if isinstance(expected_code, Number) and response.status_code != expected_code \
--- 76,78 ----
          url = self._get_url(path)
!         response = self.session.request(method, url, allow_redirects=False, **kwargs)
          if isinstance(expected_code, Number) and response.status_code != expected_code \

To get around this problem I have just uncommented the 'f.write(response.content)' on line 126 in client.py (and added a comment to 'shutil.copyfileobj(response.raw, f)' on line 127).

As far as I can see using response.raw and something like shutil.copyfileobj() is however necessary to be able to download really large files.

How to get/put a whole dir

When I call webdav.download('remotedir/', 'localdir/') , it dispatchs a error says that 'localdir/' is a directory.

Is it possible to move file to a different path?

Is this possible to call a rest api to move file from current directory to a different directory?

Download => Upload to destination path => Remove file seems to be an overcome solutions, but it maintain risks and slow performance

null valued contentlength prop on zope

in function elem2file() prop(elem, 'getcontentlength', 0) call returns None because child is not None but child.text is None, you should use something link return default if child is None or child.text is None else child.text

What is "safe=False"?

I can't see any usage of this param into source code.
For what did you create it?

OneDrive returns 302 Found on PROPFIND

Traceback (most recent call last):
File "davput.py", line 24, in
print webdav.ls()
File "/usr/local/lib/python2.7/dist-packages/easywebdav/client.py", line 176, in ls
response = self._send('PROPFIND', remote_path, (207, 301), headers=headers)
File "/usr/local/lib/python2.7/dist-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 UNKNOWN, 301 Moved Permanently
Actual code : 302 Found

The WebDAV address used is of the format: https://d.docs.live.net/(cid here)/

Potential for wrong download file size?

In the download function, it's currently set to use response.raw, via shutil.copyfileobj. It's easy to see that this avoids loading the whole downloaded file into memory, as opposed to the commented out line next to it that just writes response.content.

However, if I'm reading the 'requests' documentation correctly, response.content will automatically handle gzip/deflate and result in the correct file if the server uses these, while response.raw, being genuinely raw socket data, will not handle this, and the resulting file will not be what is expected.

Am I right or not? I don't currently have a compliant server to test that against.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.