Skip to content

Commit c891eb8

Browse files
committed
Quote password in URL
By default, the username and password are passed to each request to the API using Basic authentication. From the `xmlrpc.client` doc: ``` Both the HTTP and HTTPS transports support the URL syntax extension for HTTP Basic Authentication: http://user:pass@host:port/path. The user:pass portion will be base64-encoded as an HTTP ‘Authorization’ header, and sent to the remote server as part of the connection process when invoking an XML-RPC method. ``` So this lib generate an URL containing the username and the password. If the password contained some characters (cf https://datatracker.ietf.org/doc/html/rfc3986.html#section-2.2), the URL became invalid. By simply using `urllib.parse.quote` on the password, the problem is solved. From a quick test, Dokuwiki seems to remove special characters from username so only the password requires quoting. Setting the `cookieAuth` parameter would have prevented the problem. When set, the session is kept using cookies (via the HTTP headers) and only one call to the *login* endpoint is done (and the password is not wrappred in the URL). Fix #24
1 parent c1429d5 commit c891eb8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

dokuwiki.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
PY_VERSION = sys.version_info[0]
2525
if PY_VERSION == 3:
2626
from xmlrpc.client import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError
27-
from urllib.parse import urlencode
27+
from urllib.parse import quote
2828
else:
2929
from xmlrpclib import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError
30-
from urllib import urlencode
30+
from urllib import quote
3131

3232
from datetime import datetime, timedelta
3333

@@ -154,7 +154,7 @@ def __init__(self, url, user, password, **kwargs):
154154
raise DokuWikiError("invalid url '%s'" % url)
155155

156156
# Set auth string or transport for cookie based authentication.
157-
auth = '{:s}:{:s}@'.format(user, password)
157+
auth = '{:s}:{:s}@'.format(user, quote(password))
158158
cookie_auth = kwargs.pop('cookieAuth', False)
159159
if cookie_auth:
160160
auth = ''

0 commit comments

Comments
 (0)