|
23 | 23 |
|
24 | 24 | PY_VERSION = sys.version_info[0]
|
25 | 25 | if PY_VERSION == 3:
|
26 |
| - from xmlrpc.client import ServerProxy, Binary, Fault, Transport, SafeTransport |
| 26 | + from xmlrpc.client import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError |
27 | 27 | from urllib.parse import urlencode
|
28 | 28 | else:
|
29 |
| - from xmlrpclib import ServerProxy, Binary, Fault, Transport, SafeTransport |
| 29 | + from xmlrpclib import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError |
30 | 30 | from urllib import urlencode
|
31 | 31 |
|
32 | 32 | from datetime import datetime, timedelta
|
@@ -155,19 +155,27 @@ def __init__(self, url, user, password, **kwargs):
|
155 | 155 |
|
156 | 156 | # Set auth string or transport for cookie based authentication.
|
157 | 157 | auth = '{:s}:{:s}@'.format(user, password)
|
158 |
| - if kwargs.pop('cookieAuth', False): |
| 158 | + cookie_auth = kwargs.pop('cookieAuth', False) |
| 159 | + if cookie_auth: |
159 | 160 | auth = ''
|
160 | 161 | kwargs['transport'] = CookiesTransport(params['proto'])
|
161 | 162 |
|
162 | 163 | xmlrpc_url = '%s://%s%s%s/lib/exe/xmlrpc.php' % (
|
163 | 164 | params['proto'], auth, params['host'], params['uri'] or '')
|
164 | 165 | self.proxy = ServerProxy(xmlrpc_url, **kwargs)
|
165 | 166 |
|
166 |
| - # Force login (required for cookie based authentication and allows |
167 |
| - # to check the connection). |
168 |
| - if not self.login(user, password): |
| 167 | + # Force login for cookie based authentication. |
| 168 | + if cookie_auth and not self.login(user, password): |
169 | 169 | raise DokuWikiError('invalid login or password!')
|
170 | 170 |
|
| 171 | + # Dummy call to ensure the connection is up. |
| 172 | + try: |
| 173 | + self.version |
| 174 | + except ProtocolError as err: |
| 175 | + if err.errcode == 401: |
| 176 | + raise DokuWikiError('invalid login or password!') |
| 177 | + raise |
| 178 | + |
171 | 179 | # Set "namespaces" for pages and medias functions.
|
172 | 180 | self.pages = _Pages(weakref.ref(self)())
|
173 | 181 | self.medias = _Medias(weakref.ref(self)())
|
|
0 commit comments