EnterpriseyIntranet / nextcloud-API

NextCloud OCS API for Python
GNU General Public License v3.0
27 stars 27 forks source link

Create/delete group folders (and possibly other XML-based methods) are broken #57

Open blacklight opened 4 years ago

blacklight commented 4 years ago

Example:

>>> from nextcloud import NextCloud
>>> nc = NextCloud(url, user, pwd)
>>> >>> nc.create_group_folder('Test folder')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/nextcloud/api_wrappers/group_folders.py", line 40, in create_group_folder
    return self.requester.post(data={"mountpoint": mountpoint})
  File "/usr/lib/python3.8/site-packages/nextcloud/requester.py", line 16, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/nextcloud/requester.py", line 54, in post
    return self.rtn(res)
  File "/usr/lib/python3.8/site-packages/nextcloud/requester.py", line 106, in rtn
    return OCSResponse(response=resp,
  File "/usr/lib/python3.8/site-packages/nextcloud/response.py", line 52, in __init__
    self.full_data = response.json()
  File "/usr/lib/python3.8/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After some debugging it looks like the response sent by the server looks like this:

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>100</statuscode>
  <message>OK</message>
  <totalitems></totalitems>
  <itemsperpage></itemsperpage>
 </meta>
 <data/>
</ocs>

However, the OCSRequester treats the output as a JSON and it breaks.

I believe that some methods return XML regardless of the format=json parameter on the request, and the library should probably be robust enough to detect such cases and parse the response appropriately.

matejak commented 4 years ago

Thanks for the report, would you mind to create a PR with tests that expose this?