mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-28 18:14:42 +00:00
Merge pull request #132 from linkcheck/fix-cookie-loading
Fix internal error when using cookies
This commit is contained in:
commit
279e6a2f3a
3 changed files with 16 additions and 1 deletions
|
|
@ -34,6 +34,7 @@ from .. import log, LOG_CHECK, strformat, LinkCheckerError
|
|||
from ..decorators import synchronized
|
||||
from ..cache import urlqueue
|
||||
from ..htmlutil import formsearch
|
||||
from ..cookies import from_file
|
||||
from . import logger, status, checker, interrupt
|
||||
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ def new_request_session(config, cookies):
|
|||
"User-Agent": config["useragent"],
|
||||
})
|
||||
if config["cookiefile"]:
|
||||
for cookie in cookies.from_file(config["cookiefile"]):
|
||||
for cookie in from_file(config["cookiefile"]):
|
||||
session.cookies = requests.cookies.merge_cookies(session.cookies, cookie)
|
||||
return session
|
||||
|
||||
|
|
|
|||
3
tests/cookies.txt
Normal file
3
tests/cookies.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Host: example.org
|
||||
Path: /hello
|
||||
Set-cookie: om="nomnom"
|
||||
|
|
@ -18,8 +18,12 @@
|
|||
Test cookie routines.
|
||||
"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import linkcheck.cookies
|
||||
import linkcheck.configuration
|
||||
import linkcheck.director
|
||||
|
||||
|
||||
class TestCookies (unittest.TestCase):
|
||||
|
|
@ -66,3 +70,10 @@ class TestCookies (unittest.TestCase):
|
|||
]
|
||||
from_headers = linkcheck.cookies.from_headers
|
||||
self.assertRaises(ValueError, from_headers, "\r\n".join(lines))
|
||||
|
||||
def test_cookie_file (self):
|
||||
config = linkcheck.configuration.Configuration()
|
||||
here = os.path.dirname(__file__)
|
||||
config['cookiefile'] = os.path.join(here, 'cookies.txt')
|
||||
aggregate = linkcheck.director.get_aggregate(config)
|
||||
aggregate.add_request_session()
|
||||
|
|
|
|||
Loading…
Reference in a new issue