TokenError: debug info
This commit is contained in:
parent
e91824f478
commit
b79efb22d4
1 changed files with 27 additions and 6 deletions
|
@ -7,7 +7,7 @@ import logging
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Dict, Any
|
from typing import List, Dict, Any
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ REQUA = \
|
||||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' \
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' \
|
||||||
'(KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.47'
|
'(KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.47'
|
||||||
|
|
||||||
|
ARROW_FN_REGEX = r'\(\(\)(.*?)\)\(\);'
|
||||||
|
SCRIPT_TAG_REGEX = (
|
||||||
|
rb'<script type=([\'"]?)text/javascript\1>.+?</script>'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AternosConnect:
|
class AternosConnect:
|
||||||
|
|
||||||
|
@ -101,17 +106,19 @@ class AternosConnect:
|
||||||
# Some checks
|
# Some checks
|
||||||
if headtag < 0 or headend < 0:
|
if headtag < 0 or headend < 0:
|
||||||
pagehead = loginpage
|
pagehead = loginpage
|
||||||
raise RuntimeWarning(
|
logging.warning(
|
||||||
'Unable to find <head> tag, parsing the whole page'
|
'Unable to find <head> tag, parsing the whole page'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
# Extracting <head> content
|
# Extracting <head> content
|
||||||
headtag = headtag + len(head)
|
headtag = headtag + len(head)
|
||||||
pagehead = loginpage[headtag:headend]
|
pagehead = loginpage[headtag:headend]
|
||||||
|
|
||||||
|
js_code: Optional[List[Any]] = None
|
||||||
try:
|
try:
|
||||||
text = pagehead.decode('utf-8', 'replace')
|
text = pagehead.decode('utf-8', 'replace')
|
||||||
js_code = re.findall(r'\(\(\)(.*?)\)\(\);', text)
|
js_code = re.findall(ARROW_FN_REGEX, text)
|
||||||
|
|
||||||
token_func = js_code[0]
|
token_func = js_code[0]
|
||||||
if len(js_code) > 1:
|
if len(js_code) > 1:
|
||||||
|
@ -121,6 +128,20 @@ class AternosConnect:
|
||||||
self.token = ctx.window['AJAX_TOKEN']
|
self.token = ctx.window['AJAX_TOKEN']
|
||||||
|
|
||||||
except (IndexError, TypeError) as err:
|
except (IndexError, TypeError) as err:
|
||||||
|
|
||||||
|
logging.warning('---')
|
||||||
|
logging.warning('Unable to parse AJAX_TOKEN!')
|
||||||
|
logging.warning('Please, insert the info below')
|
||||||
|
logging.warning('to the GitHub issue description:')
|
||||||
|
logging.warning('---')
|
||||||
|
|
||||||
|
logging.warning('JavaScript: %s', js_code)
|
||||||
|
logging.warning(
|
||||||
|
'All script tags: %s',
|
||||||
|
re.findall(SCRIPT_TAG_REGEX, pagehead)
|
||||||
|
)
|
||||||
|
logging.warning('---')
|
||||||
|
|
||||||
raise TokenError(
|
raise TokenError(
|
||||||
'Unable to parse TOKEN from the page'
|
'Unable to parse TOKEN from the page'
|
||||||
) from err
|
) from err
|
||||||
|
|
Reference in a new issue