diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 9bb8baf..e173e0d 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.5.3' +__version__ = '4.0.5.4' diff --git a/DrissionPage/_pages/session_page.py b/DrissionPage/_pages/session_page.py index 4f699c8..94a7d07 100644 --- a/DrissionPage/_pages/session_page.py +++ b/DrissionPage/_pages/session_page.py @@ -292,23 +292,25 @@ class SessionPage(BasePage): """ kwargs = CaseInsensitiveDict(kwargs) if 'headers' not in kwargs: - kwargs['headers'] = {} + kwargs['headers'] = CaseInsensitiveDict() else: kwargs['headers'] = CaseInsensitiveDict(format_headers(kwargs['headers'])) # 设置referer和host值 parsed_url = urlparse(url) - hostname = parsed_url.hostname + hostname = parsed_url.netloc scheme = parsed_url.scheme if not check_headers(kwargs['headers'], self._headers, 'Referer'): kwargs['headers']['Referer'] = self.url if self.url else f'{scheme}://{hostname}' - if 'Host' not in kwargs['headers']: + if not check_headers(kwargs['headers'], self._headers, 'Host'): kwargs['headers']['Host'] = hostname - if not check_headers(kwargs, self._headers, 'timeout'): kwargs['timeout'] = self.timeout - kwargs['headers'] = {**self._headers, **kwargs['headers']} + h = CaseInsensitiveDict(self._headers) + for k, v in kwargs['headers'].items(): + h[k] = v + kwargs['headers'] = h r = err = None retry = retry if retry is not None else self.retry_times