update csrf token in urlopen_json

This commit is contained in:
mohammed akmal miah 2022-01-17 12:30:07 +00:00
parent 0563b54fc6
commit 16541c522e
1 changed files with 4 additions and 0 deletions

View File

@ -118,6 +118,10 @@ class RefineServer(object):
"""Open a Refine URL, optionally POST data, and return parsed JSON."""
response = json.loads(self.urlopen(*args, **kwargs).read())
if 'code' in response and response['code'] not in ('ok', 'pending'):
if 'Missing or invalid csrf_token parameter' == response['message']:
self.get_csrf_token()
response = json.loads(self.urlopen(*args, **kwargs).read())
return response
error_message = ('server ' + response['code'] + ': ' +
response.get('message', response.get('stack', response)))
raise Exception(error_message)