owncloud / pyocclient

ownCloud client library for Python
MIT License
295 stars 115 forks source link

share_file_with_link OCS error 996 #259

Open CrohnEngineer opened 3 years ago

CrohnEngineer commented 3 years ago

Hey everybody,

following the usage example, I'm writing a simple script to put a file on OwnCloud and then share it with a link. Everything goes fine, until I call oc.share_file_with_link(remote_file_path), when the error stack trace reports a OSC error 996 (which, if I'm not mistaken, corresponds to a server error). Can anybody suggest me what is happening here? Has anyone else encountered this issue before? I anticipate that I use pyocclient 0.6, but I do not manage the OC server directly, so I might miss some information on that side. Thank you in advance!

landryb commented 3 years ago

Not sure 100% related to your issue since you didnt post code, there seems to be a regression from commit 5aa5b93 which inconditionally checks that the server replied with a 'name' attribute, which doesnt seem to be the case with nextcloud 21.

here's a simple reproducer:

import owncloud
import sys

oc = owncloud.Client('https://fqdn', debug=True)
oc.login('ncadmin','xxx')

try:
    print("share: {}".format(oc.share_file_with_link('orgs/COM_TEST', password='pass')))
except owncloud.HTTPResponseError as e:
    print("Exception: {}".format(e))
    sys.exit()

oc.logout()

which gives:

OCS request: POST https://fqdn/ocs/v1.php/apps/files_sharing/api/v1/shares {'data': {'shareType': 3, 'path': '/orgs/COM_TEST', 'password': 'pass'}, 'headers': {'OCS-APIREQUEST': 'true'}}
Traceback (most recent call last):
  File "datamisc/tests/test_share_file_with_link_pyocc06.py", line 16, in <module>
    print("share: {}".format(oc.share_file_with_link('orgs/COM_TEST', password='pass')))
  File "/home/landry/scratch/venv/lib/python3.7/site-packages/owncloud/owncloud.py", line 910, in share_file_with_link
    'name': data_el.find('name').text
AttributeError: 'NoneType' object has no attribute 'text'

sadly, it seems to be the same if you pass a name argument to the method, so i dunno against which server it was tested/developed (owncloud ? nextcloud ?) nor which version but that feels broken. @PVince81 ?

looking at the doc (not sure its the right/latest one ?) name isnt mentioned on https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html#create-a-new-share but it is on https://doc.owncloud.com/server/developer_manual/core/apis/ocs-share-api.html#create-a-new-share so i'd say this is only working with owncloud ?

testing via curl, there's no name attribute in the returned XML for nextcloud 21.

$curl -u ncadmin -H "OCS-APIREQUEST: true" -X POST -dpath=/orgs/COM_TEST -dpassword=pass -dshareType=3 https://fqdn/ocs/v1.php/apps/files_sharing/api/v1/shares
Enter host password for user 'ncadmin':
<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>100</statuscode>
  <message>OK</message>
  <totalitems></totalitems>
  <itemsperpage></itemsperpage>
 </meta>
 <data>
  <id>41</id>
  <share_type>3</share_type>
  <uid_owner>ncadmin</uid_owner>
  <displayname_owner>ncadmin</displayname_owner>
  <permissions>17</permissions>
  <can_edit>1</can_edit>
  <can_delete>1</can_delete>
  <stime>1615554587</stime>
  <parent/>
  <expiration/>
  <token>cbiNfrBs49idf6T</token>
  <uid_file_owner>ncadmin</uid_file_owner>
  <note></note>
  <label></label>
  <displayname_file_owner>ncadmin</displayname_file_owner>
  <path>/orgs/COM_TEST</path>
  <item_type>folder</item_type>
  <mimetype>httpd/unix-directory</mimetype>
  <has_preview></has_preview>
  <storage_id>local::/data/web/nextcloud/data/</storage_id>
  <storage>2</storage>
  <item_source>6475</item_source>
  <file_source>6475</file_source>
  <file_parent>2174</file_parent>
  <file_target>/COM_TEST</file_target>
  <share_with>xxxxx</share_with>
  <share_with_displayname>(Lien partagé)</share_with_displayname>
  <password>xxx</password>
  <send_password_by_talk></send_password_by_talk>
  <url>https://fqdn/s/cbiNfrBs49idf6T</url>
  <mail_send>1</mail_send>
  <hide_download>0</hide_download>
 </data>
</ocs>
CrohnEngineer commented 3 years ago

Hey @landryb ,

Not sure 100% related to your issue since you didnt post code,

sorry about this, but as I wrote in my first post I simply used the code provided in the README.md. So, just using this code snippet:

import owncloud

oc = owncloud.Client('http://domain.tld/owncloud')

oc.login('user', 'password')

oc.mkdir('testdir')

oc.put_file('testdir/remotefile.txt', 'localfile.txt')

link_info = oc.share_file_with_link('testdir/remotefile.txt')

print "Here is your link: " + link_info.get_link() 

gives me the aforementioned OSCError 996. Using the code snippet you provided gives me the same error, with the same error stack trace (see below):

Traceback (most recent call last):
  File "owncloud_file_testing.py", line 8, in <module>
    print("share: {}".format(oc.share_file_with_link('zip_folders.py', password='pass')))
  File "/nas/home/ecannas/miniconda3/lib/python3.7/site-packages/owncloud/owncloud.py", line 902, in share_file_with_link
    self._check_ocs_status(tree)
  File "/nas/home/ecannas/miniconda3/lib/python3.7/site-packages/owncloud/owncloud.py", line 1738, in _check_ocs_status
    raise OCSResponseError(r)
owncloud.owncloud.OCSResponseError: OCS error: 996

Therefore, it seems to me that my issue is unrelated to the one you are mentioning. Any thoughts about it? Anyway, thanks for passing by and sorry for the delay in answering you. Bests,

Edoardo

landryb commented 3 years ago

well, if you're using pyocclient against owncloud, no i dont think that's the same issue :)

CrohnEngineer commented 3 years ago

Good to know!

luffah commented 3 years ago

Similar bugs #218, #259. #263 (with a simple fix proposal - a mere workaround)

dogganos commented 1 year ago

Any news on this? Same problem after upgrading owncloud to: ./occ status

I increased verbosity level on owncloud server to debug and while I get logs while the login is happening and while the upload is happening, I get nothing in the logs when the server sends this 996 error, which in the owncloud documentation is supposed to be 'internal server error'.

lathass-123 commented 12 months ago

@CrohnEngineer , Any solution for the error oc.share_file_with_link() raising 996 error? Can any one help here?

CrohnEngineer commented 12 months ago

Hey @lathass-123 ,

I found a turnaround by using the same code but disabling the SSL credentials check; however, I would not advise doing that since it is not safe from a security point of view.
To be honest, since no answer came from this thread, and I don't like sharing my credentials in the clear over the Web, I stopped using the library years ago :)
I hope you have better luck than me!

lathass-123 commented 12 months ago

Hey CrohnEngineer,

Thank you for the update. I will check what i can do.