python-caldav / caldav

Apache License 2.0
312 stars 91 forks source link

Error 405 when using Propfind on some webdav servers #396

Closed veni-vidi-code closed 1 month ago

veni-vidi-code commented 1 month ago

Hey, when initialising the principal using get_principal using client.principal() returns 405 Not Allowed on some servers (e.g. openxchange). Interestingly enough when initialising it using client.principal(url=x) where xis the same url the client was initiated with it works. As the urlparameter is depreceated i think this should be adressed in some way by either undepreceating it or adding some sort of attempt to use the unaltered url as fallback

veni-vidi-code commented 1 month ago

also see https://git.fsmpi.rwth-aachen.de/protokollsystem/proto3/-/issues/224 if you understand german

tobixen commented 1 month ago

As I read the code, writingclient.principal(url=x) should be equivalent with writing Principal(client=client, url=x). The URL given there should be the URL to the principal (i.e. somehting like https://caldav.my.calendar/users/tobixen), and not the URL to he caldav server. (i.e. something like https://caldav.my.calendar/) When not giving an URL, the library will try to auto-detect the principal URL.

At some point I was optimistically assuming the auto-detection (through the PROPFIND method) would work on any calendar server, but I was wrong (it's not even a requirement in the RFC to support this method). Now, since OX gives 405 it most likely is one of the rare servers not supporting this.

One workaround here could be to fix the code to try doing a client.principal(url=client.url) if the server doesn't support PROPFIND.

Since I don't have OX and don't have time looking into OX itself, it would be very useful if you could provide me with a test account on OX that I could use to run the test code.

tobixen commented 1 month ago

This may be related to #180

veni-vidi-code commented 1 month ago

Hey, sadly i do not have the permissions to create you a user on our server, i might talk to one of our admins within the next weeks though. Local hosting is also not an option, just for testing there licenses are to expensive. They do offer a test instance (The big green demo button on https://www.open-xchange.com/), but i can not figure out the caldav auth data there.

Some more information though: The problem is in principal.calender_home_set, more specific calendar_home_set_url = self.get_property(cdav.CalendarHomeSet()). If the principal url is set to https://example.com/caldav/ (which gets port 443 added to it) it works as intended and returns /caldav/. If no url gets passed principal.url returns https://example.com:443/principals/users/someid (someid is just numbers) on which the propfind returns <html>\n<head><title>405 Not Allowed</title></head>\n<body bgcolor="white">\n<center><h1>405 Not Allowed</h1></center>\n<hr><center>nginx/versionnumber</center>\n</body>\n</html>\n.

veni-vidi-code commented 1 month ago

I just noticed some more reasons that might be causing this whit openxchange. I will talk to our admins and reopen this ticket as needed

tobixen commented 1 month ago

I could try to send an email to the OX team and ask if it's possible to use the demo environment for this purpose.