fix:
This commit is contained in:
parent
92da8114c3
commit
75a0b5055e
@ -1,6 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
from requets.Session import Session
|
from requests import Response, Request, Session
|
||||||
from requests import Response, Requests
|
|
||||||
|
|
||||||
import urls
|
import urls
|
||||||
|
|
||||||
@ -9,22 +8,23 @@ class Client:
|
|||||||
self.url: str = url
|
self.url: str = url
|
||||||
self.token: str = None
|
self.token: str = None
|
||||||
self.session: Session = Session()
|
self.session: Session = Session()
|
||||||
response: Response = s.get(self.url)
|
|
||||||
self.csrf_token = response.cookies['csrftoken']
|
|
||||||
|
|
||||||
def is_authentificate(self: Client):
|
def is_authentificate(self):
|
||||||
return (not self.token is None)
|
return (not self.token is None)
|
||||||
|
|
||||||
def login(self: Client, username: str, password: str):
|
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_url, {'username': username, 'password': password})
|
||||||
return response.content
|
return response.content
|
||||||
|
|
||||||
def register(self: Client, username: str, password: str):
|
def register(self, username: str, password: str):
|
||||||
response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password})
|
response: Response = self._post(urls.accounts_register_url, {'username': username, 'password': password})
|
||||||
return response.content
|
return response
|
||||||
|
|
||||||
def _post(self: Client, uri: str, data: dict):
|
def _post(self, uri: str, data: dict):
|
||||||
url: str = self.url + uri
|
url: str = self.url + uri
|
||||||
data.update({'csrfmiddlewaretoken': self.csrf_token})
|
if self.token is None:
|
||||||
response: Response = s.post(url, data = data, headers = dict(Referer=url))
|
response: Response = self.session.get(url)
|
||||||
|
self.token = response.cookies['csrftoken']
|
||||||
|
data.update({'csrfmiddlewaretoken': self.token})
|
||||||
|
response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
|
||||||
return response.content
|
return response.content
|
Loading…
Reference in New Issue
Block a user