diff --git a/src/Client.py b/src/Client.py index 93adeeb..bf21a88 100644 --- a/src/Client.py +++ b/src/Client.py @@ -13,18 +13,15 @@ class Client: return (not self.token is None) def login(self, username: str, password: str): - response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) + response: Response = self._post(urls.accounts_login, {'username': username, 'password': password}) return response.content - def register(self, username: str, password: str): - response: Response = self._post(urls.accounts_register_url, {'username': username, 'password': password}) - return response - - def _post(self, uri: str, data: dict): + def _post(self, uri: str, data: dict = {}): url: str = self.url + uri if self.token is None: response: Response = self.session.get(url) - self.token = response.cookies['csrftoken'] + self.token = response.cookies.get('csrftoken') data.update({'csrfmiddlewaretoken': self.token}) response: Response = self.session.post(url, data = data, headers = dict(Referer=url)) - return response.content \ No newline at end of file + self.token = response.cookies.get('csrftoken') + return response \ No newline at end of file