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

owncloud.Client.file_info() is not returning None when file is not found. #250

Open
ericlincc opened this issue Oct 28, 2020 · 4 comments
Open

Comments

@ericlincc
Copy link

ericlincc commented Oct 28, 2020

According to line 416, owncloud.Client.file_info() should return None if file is not found. Instead an HTTPResponseError: HTTP error: 404 is thrown.

According to OwnCloud's developer manual, an HTTP/1.1 404 Not Found is the expected response if file is not found. Currently, an exception is thrown by owncloud.Client._make_dav_request() and it has not been caught in owncloud.Client.file_info().

EDIT:
Suggestion: Amend the description of file_info(), or add a feature to check if file exists without resulting a 404 Not Found Error.

@landryb
Copy link

landryb commented Nov 12, 2020

i've just stumbled upon this issue, as suddenly after a change in my infra all file_info() calls on non-existent files/dirs started throwing exceptions. Turns out that removing those lines in my virtualhost/nginx config (nextcloud/documentation@daa543e) started triggering this, and readding those two lines to my nginx config, file_info() calls properly return None on missing files/dirs. That's ... puzzling.

Imo, the exception should be catched/handled inside file_info().

@landryb
Copy link

landryb commented Mar 12, 2021

@PVince81 since you recently commited again to this module and made a release, can you have a look at this issue, at least acknowledging it ? thanks !

@landryb
Copy link

landryb commented Mar 12, 2021

i've tested this against pyocclient 0.4, first test when doing file_info on a non existing file on a nginx instance with the two error_page lines present:

[12/03 10:10] [email protected]:~/scratch/autoshare $../venv/bin/python3 datamisc/tests/test_occlient_bug_250_missing.py
OCS request: GET https://drive.dev.craig.fr/ocs/v1.php/cloud/capabilities {'headers': {'OCS-APIREQUEST': 'true'}}
DAV request: PROPFIND doesntexist
Headers:  {'Depth': '0'}
DAV status: 200
Exists: None

commented out the two lines in the nginx config, reloaded it:

[12/03 10:10] [email protected]:~/scratch/autoshare $../venv/bin/python3 datamisc/tests/test_occlient_bug_250_missing.py
OCS request: GET https://drive.dev.craig.fr/ocs/v1.php/cloud/capabilities {'headers': {'OCS-APIREQUEST': 'true'}}
DAV request: PROPFIND doesntexist
Headers:  {'Depth': '0'}
DAV status: 404
Exception: HTTP error: 404

the test code is:

import owncloud
import sys

oc = owncloud.Client('https://drive.dev.craig.fr', debug=True)
oc.login('ncadmin','xxxx')

try:
    print("exists:{}".format(oc.file_info('doesntexist')))
except owncloud.HTTPResponseError as e:
    print("exception:{}".format(e))
    sys.exit()

oc.logout()

done the same test against pyocclient 0.6:

[12/03 10:16] [email protected]:~/scratch/autoshare $sudo ../venv/bin/pip3 install pyocclient==0.6

that produces the same exact result, so the issue is still present.

@landryb
Copy link

landryb commented Mar 12, 2021

of course, a workaround client side would be to wrap all file_info calls within try/except HTTPResponseError:

try:
    file = oc.file_info(path)
except owncloud.HTTPResponseError:
    file = None

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