mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Fix library: my_requests
This commit is contained in:
parent
d65865a26c
commit
891f14b6a3
@ -61,7 +61,6 @@ def get_token(site_name: str, domain: str) -> dict:
|
|||||||
find_csrf_token = html_meta.get('content')
|
find_csrf_token = html_meta.get('content')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'XSRF_TOKEN': response.cookies['XSRF-TOKEN'],
|
|
||||||
'animeunity_session': response.cookies['animeunity_session'],
|
'animeunity_session': response.cookies['animeunity_session'],
|
||||||
'csrf_token': find_csrf_token
|
'csrf_token': find_csrf_token
|
||||||
}
|
}
|
||||||
|
@ -209,41 +209,35 @@ class ManageRequests:
|
|||||||
|
|
||||||
def _build_request(self) -> urllib.request.Request:
|
def _build_request(self) -> urllib.request.Request:
|
||||||
"""Build the urllib Request object."""
|
"""Build the urllib Request object."""
|
||||||
|
|
||||||
|
# Make a copy of headers to avoid modifying the original dictionary
|
||||||
headers = self.headers.copy()
|
headers = self.headers.copy()
|
||||||
|
|
||||||
|
# Construct the URL with query parameters if present
|
||||||
if self.params:
|
if self.params:
|
||||||
url = self.url + '?' + urllib.parse.urlencode(self.params)
|
url = self.url + '?' + urllib.parse.urlencode(self.params)
|
||||||
else:
|
else:
|
||||||
url = self.url
|
url = self.url
|
||||||
|
|
||||||
|
# Create the initial Request object
|
||||||
req = urllib.request.Request(url, headers=headers, method=self.method)
|
req = urllib.request.Request(url, headers=headers, method=self.method)
|
||||||
|
|
||||||
|
# Add JSON data if provided
|
||||||
if self.json_data:
|
if self.json_data:
|
||||||
req.add_header('Content-Type', 'application/json')
|
req.add_header('Content-Type', 'application/json')
|
||||||
req.body = json.dumps(self.json_data).encode('utf-8')
|
req.data = json.dumps(self.json_data).encode('utf-8')
|
||||||
else:
|
|
||||||
req = urllib.request.Request(url, headers=headers, method=self.method)
|
|
||||||
|
|
||||||
|
# Add authorization header if provided
|
||||||
if self.auth:
|
if self.auth:
|
||||||
req.add_header('Authorization', 'Basic ' + base64.b64encode(f"{self.auth[0]}:{self.auth[1]}".encode()).decode())
|
req.add_header('Authorization', 'Basic ' + base64.b64encode(f"{self.auth[0]}:{self.auth[1]}".encode()).decode())
|
||||||
|
|
||||||
|
# Add cookies if provided
|
||||||
if self.cookies:
|
if self.cookies:
|
||||||
cookie_str = '; '.join([f"{name}={value}" for name, value in self.cookies.items()])
|
cookie_str = '; '.join([f"{name}={value}" for name, value in self.cookies.items()])
|
||||||
req.add_header('Cookie', cookie_str)
|
req.add_header('Cookie', cookie_str)
|
||||||
|
|
||||||
if self.headers:
|
# Add default user agent if not already present
|
||||||
for key, value in self.headers.items():
|
if 'user-agent' not in headers:
|
||||||
req.add_header(key, value)
|
|
||||||
|
|
||||||
# Add default user agent
|
|
||||||
if True:
|
|
||||||
there_is_agent = False
|
|
||||||
|
|
||||||
for key, value in self.headers.items():
|
|
||||||
if str(key).lower() == 'user-agent':
|
|
||||||
there_is_agent = True
|
|
||||||
|
|
||||||
if not there_is_agent:
|
|
||||||
default_user_agent = 'Mozilla/5.0'
|
default_user_agent = 'Mozilla/5.0'
|
||||||
req.add_header('user-agent', default_user_agent)
|
req.add_header('user-agent', default_user_agent)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user