From 043de1bda4f5ab68d5c56fec1227be0fff78c0a6 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Wed, 2 Feb 2022 17:19:20 +1100 Subject: [PATCH] proper csrf method, remove temporary hack --- session.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/session.py b/session.py index 3f98be2..617f3cd 100644 --- a/session.py +++ b/session.py @@ -36,20 +36,12 @@ class ModSession(Session): def update_csrf(self): try: - -# res = self.get(url=f'{self.imageboard_url}/csrf.json', -# headers={'Referer': f'{self.imageboard_url}/csrf.json'}).json() -# if 'token' in res: -# self.csrf_token = res['token'] -# else: -# raise Exception('Unable to update csrf token') - - #temporary hack to get csrf token to test on <=0.1.10 - res2 = self.get(url=f'{self.imageboard_url}/account.html', - headers={'Referer': f'{self.imageboard_url}/account.html'}) - csrfi = res2.text.index('_csrf') - self.csrf_token = res2.text[csrfi+14:csrfi+50] - + res = self.get(url=f'{self.imageboard_url}/csrf.json', + headers={'Referer': f'{self.imageboard_url}/csrf.json'}).json() + if 'token' in res: + self.csrf_token = res['token'] + else: + raise Exception('Unable to update csrf token') except requests.RequestException as e: logging.error(f'Exception {e} occurred while updating csrf token') raise Exception('Unable to update csrf token')