-
Notifications
You must be signed in to change notification settings - Fork 7
/
mwapi_utils.py
26 lines (24 loc) · 1.07 KB
/
mwapi_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import mwapi # type: ignore
import sys
class T272319RetryingSession(mwapi.Session):
"""Session subclass that retries requests once on certain errors"""
def get(self, *args, **kwargs):
try:
return super().get(*args, **kwargs)
except mwapi.errors.APIError as e:
if e.code == 'mwoauth-invalid-authorization' and 'Nonce already used' in e.info:
print('Got “Nonce already used” error (T272319), retrying:', file=sys.stderr)
print(e, file=sys.stderr)
return super().get(*args, **kwargs)
else:
raise e
def post(self, *args, **kwargs):
try:
return super().post(*args, **kwargs)
except mwapi.errors.APIError as e:
if e.code == 'mwoauth-invalid-authorization' and 'Nonce already used' in e.info:
print('Got “Nonce already used” error (T272319), retrying:', file=sys.stderr)
print(e, file=sys.stderr)
return super().post(*args, **kwargs)
else:
raise e