Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get csrf_token issue #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pyinstalive/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

def get_csrf_token():
response = globals.session.session.get(Constants.LOGIN_PAGE)
return helpers.get_shared_data(response.text).get("csrf_token", None)
helper_res = helpers.get_shared_data(response.text)
return helper_res.get("csrf_token", None)

def do_login():
now_epoch = int(datetime.now().timestamp())
Expand Down
22 changes: 18 additions & 4 deletions pyinstalive/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shlex
import shutil
import requests
from bs4 import BeautifulSoup

from urllib.parse import urlparse

Expand Down Expand Up @@ -86,10 +87,23 @@ def get_shared_data(data):
match_str = match.group(1)
return json.loads(match_str).get("config")
else:
match = re.search(r"\"raw\":\"({[^\n]*\\\"})", data)
if match:
match_str = string_escape(match.group(1))
return json.loads(match_str)
response = {}
soup = BeautifulSoup(data, 'html.parser')
all_scripts = soup.find_all('script', {"data-content-len":True, "src": False})
chnk_len = 100
for script in all_scripts:
if int(script["data-content-len"]) > 30000:
lines = script.text
for idx in range(0, len(lines), chnk_len):
csrf_token_match = re.findall(r"csrf_token", lines[idx : idx + chnk_len])
if csrf_token_match:
matches = re.findall(r'\{([^}]+)\}', lines[idx : idx + chnk_len])
if len(matches)>0:
dict_value = "{" + matches[0] + "}"
response = json.loads(dict_value)
break
return response


def lock_exists():
return os.path.isfile(os.path.join(globals.config.download_path, globals.download.download_user + '.lock'))
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
argparse>=1.4.0
configparser>=4.0.2
configparser>=4.0.2
requests==2.30.0
beautifulsoup4==4.12.2