fix: post method, csrf token and return right valu
This commit is contained in:
parent
2e680d94b6
commit
f14279b956
@ -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
|
||||
self.token = response.cookies.get('csrftoken')
|
||||
return response
|
Loading…
Reference in New Issue
Block a user