The default Python xmlrpc.client.Transport
(can be used with xmlrpc.client.ServerProxy
) does not retain cookies, which are sometimes needed for cookie based logins.
For example, the following proxy, when used with the TapaTalk API (for which the login
method uses cookies for authentication), will give a permission error when trying to modify posts.
proxy = xmlrpc.client.ServerProxy(URL, xmlrpc.client.Transport())
There are some solutions for Python 2 on the net, but they aren't compatible with Python 3.
How can I use a Transport
that retains cookies?
This is a simple
Transport
subclass that will retain all cookies:Usage:
Since
xmlrpc.client
in Python 3 has better suited hooks for this, it's much simpler than an equivalent Python 2 version.Existing answer from GermainZ works only for HTTP. After a lot of time fighting with it, there is HTTPS adaptation. Note the
context
option which is crucial.The reason for it is that ServerProxy doesn't respect
context
option related to transport, if transport is specified, so we need to use it directly in Transport constructor.Usage: