fetch("https://site.com/api/", {
"headers": {
"accept": "*/*",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"id": "12345",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://site.com/api",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
def get_data(cookies, headers):
base_url = 'https://site.com'
method_url = '/api'
with requests.Session() as session:
for cookie in cookies:
session.cookies.update(cookie)
url = base_url + method_url
response = session.get(url=url, headers=headers)
return response
cookies = browser.get_cookies()
headers = {
"accept": "*/*",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"id": id,
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
'referrer': 'https://site.com,
'referrerPolicy': 'no-referrer-when-downgrade',
'method': 'GET',
'mode': 'cors',
'credentials': 'include'
}
expected string or bytes-like object
headers = """
"accept": "*/*",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"id": id,
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
'referrer': 'https://site.com,
'referrerPolicy': 'no-referrer-when-downgrade',
'method': 'GET',
'mode': 'cors',
'credentials': 'include'
"""
'str' object has no attribute 'items'
def get_data(cookies, id):
base_url = 'https://site.com'
method_url = '/api'
headers = {
'id': str(id),
'accept': '*/*',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://site.com',
'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
'method': 'GET',
'mode': 'cors',
'credentials': 'include'
}
with requests.Session() as session:
for cookie in cookies:
session.cookies.set(cookie['name'], cookie['value'])
url = base_url + method_url
response = session.get(url=url, headers=headers)
return response