Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pysuez/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ def __init__(self, username, password, counter_id, provider, session=None, timeo
self._timeout = timeout
self.state = 0

def _get_token_1(self, content):
phrase = re.compile('csrf_token(.*)')
result = phrase.search(content)
if result is None:
return None
return result.group(1)

def _get_token_2(self, content):
phrase = re.compile('csrfToken\\\\u0022\\\\u003A\\\\u0022(.*)\\\\u0022,\\\\u0022')
result = phrase.search(content)
if result is None:
return None
return result.group(1).encode().decode('unicode_escape')

def _get_token(self):
"""Get the token"""
headers = {
Expand All @@ -55,10 +69,11 @@ def _get_token(self):
headers['Cookie'] += "; "
headers['Cookie'] += key + "=" + response.cookies[key]

phrase = re.compile('_csrf_token" value="(.*)"/>')
result = phrase.search(response.content.decode('utf-8'))
self._token = result.group(1)
self._headers = headers
decoded_content = response.content.decode('utf-8')
self._token = self._get_token_1(decoded_content) or self._get_token_2(decoded_content)
if self._token is None:
raise PySuezError("Can't get token.")

def _get_cookie(self):
"""Connect and get the cookie"""
Expand Down