JSONDecodeError when trying to use ocs with groupfolders
Closed this issue · 7 comments
nc.ocs(method="GET", path="/apps/groupfolders/folders")
results in a JSONDecodeError:
Exception has occurred: JSONDecodeError
Expecting value: line 1 column 1 (char 0)
StopIteration: 0
During handling of the above exception, another exception occurred:
File ".../nc_py_api/nc_py_api/_session.py", line 216, in ocs
response_data = loads(response.text)
^^^^^^^^^^^^^^^^^^^^
File ".../nc_py_api/nc_py_api/nextcloud.py", line 144, in ocs
return self._session.ocs(method, path, content=content, json=json, params=params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../customer-data-nextcloud/nextcloud_api_test/nc-py-api.py", line 51, in <module>
folders = nc.ocs(method="GET", path="/apps/groupfolders/folders")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Checking the response and also testing with curl, it seems that the server sends xml back per default. With curl, this can be fixed by adding -H "Accept: application/json"
- this should be done per default in the ocs function as well.
it is done in 'ocs' function, but for only for ocs
urls
_session.py:
self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/")
def _request_event_ocs(self, request: Request) -> None:
str_url = str(request.url)
if re.search(self._ocs_regexp, str_url) is not None: # this is OCS call
request.url = request.url.copy_merge_params({"format": "json"})
Ah! Could you extend this to support the groupfolders app as well? (Idk if also other apps deviate from the API like this)
I can confirm that extending the regex to self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/|/apps/groupfolders/")
seems to solve the issue already
Reference:
We can temporarily make a workaround for this..
I can confirm that extending the regex to
self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/|/apps/groupfolders/")
seems to solve the issue already
Are you sure that this works?
AFAIK, setting "format=json" works only for native OCS endpoints in Nextcloud(maybe I am wrong).
Only setting Accept: application/json
header works for my setup for groupfolder
endpoints
At least group_folders = nc.ocs(method="GET", path="/apps/groupfolders/folders")
worked without issues. I did not try all available commands though.