mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-17 09:21:17 +02:00
Fix none attributes in session headers
This commit is contained in:
parent
aa84b57a43
commit
36aa321ade
@ -20,14 +20,24 @@ from nhentai.serializer import serialize_comic_xml, serialize_json, serialize_in
|
|||||||
MAX_FIELD_LENGTH = 100
|
MAX_FIELD_LENGTH = 100
|
||||||
EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp')
|
EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp')
|
||||||
|
|
||||||
|
def get_headers():
|
||||||
|
headers = {
|
||||||
|
'Referer': constant.LOGIN_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
user_agent = constant.CONFIG.get('useragent')
|
||||||
|
if user_agent and user_agent.strip():
|
||||||
|
headers['User-Agent'] = user_agent
|
||||||
|
|
||||||
|
cookie = constant.CONFIG.get('cookie')
|
||||||
|
if cookie and cookie.strip():
|
||||||
|
headers['Cookie'] = cookie
|
||||||
|
|
||||||
|
return headers
|
||||||
|
|
||||||
def request(method, url, **kwargs):
|
def request(method, url, **kwargs):
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers.update({
|
session.headers.update(get_headers())
|
||||||
'Referer': constant.LOGIN_URL,
|
|
||||||
'User-Agent': constant.CONFIG['useragent'],
|
|
||||||
'Cookie': constant.CONFIG['cookie']
|
|
||||||
})
|
|
||||||
|
|
||||||
if not kwargs.get('proxies', None):
|
if not kwargs.get('proxies', None):
|
||||||
kwargs['proxies'] = {
|
kwargs['proxies'] = {
|
||||||
@ -39,11 +49,7 @@ def request(method, url, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
async def async_request(method, url, proxy = None, **kwargs):
|
async def async_request(method, url, proxy = None, **kwargs):
|
||||||
headers = {
|
headers=get_headers()
|
||||||
'Referer': constant.LOGIN_URL,
|
|
||||||
'User-Agent': constant.CONFIG['useragent'],
|
|
||||||
'Cookie': constant.CONFIG['cookie'],
|
|
||||||
}
|
|
||||||
|
|
||||||
if proxy is None:
|
if proxy is None:
|
||||||
proxy = constant.CONFIG['proxy']
|
proxy = constant.CONFIG['proxy']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user