alorence / django-modern-rpc

Simple XML-RPC and JSON-RPC server for modern Django
http://django-modern-rpc.rtfd.io
MIT License
98 stars 17 forks source link

XML-RPC: Response to request with pk [xyz] has content type application/json but was unable to parse it #48

Closed sean-wallace closed 1 year ago

sean-wallace commented 1 year ago

I upgraded to the latest alpha in order to try out my app with Python 3.11, and got this error. It looks like response is being returned with content-type: "application/json" even for xml-rpc endpoints.

sean-wallace commented 1 year ago

I think fix is a simple tweak to https://github.com/alorence/django-modern-rpc/blob/main/modernrpc/handlers/xmlhandler.py#L70

alorence commented 1 year ago

Thank you very much for your feedback. Indeed this was a mistake from recent changes.

I also discovered that the returned Content-Type is tested by JsonRpcTestClient (see https://github.com/alorence/django-modern-rpc/blob/main/tests/functional/conftest.py#L183) but not by XmlRpcTestClient, which is based on python builtin xmlrpc.client.ServerProxy.

I will think about a proper way to test this important part. Can I ask you which XML-RPC client complained for invalid Content-Type in response ? I may include this one in tests if possible.

Anyway, this has been fixed now, and I will check for things to update before publishing a new alpha in the next hours.

Best regards

sean-wallace commented 1 year ago

Thanks! I tried to figure out how to write a test that would catch this but got a bit lost in the test suite.

I noticed it when running python manage.py runserver locally and hitting it with Postman. I got the warning below in the runserver console, and also Postman tried to parse the xml response as if it was json, which did not work very well at all.

Response to request with pk [xyz] has content type application/json but was unable to parse it