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

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

Open
blacklight opened this issue Sep 9, 2020 · 1 comment

Comments

@blacklight
Copy link

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
Copy link

matejak commented Sep 20, 2020

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

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

2 participants