我正在尝试使用cloudscraper绕过一些webistes cloudflare waf,它工作得很好,但是,我正在特灵使用verify=False
禁用安全证书检查,如下面的代码所示,但是它抛出了一个错误
错误回溯
Traceback (most recent call last):
File "x:\documents\python\django_projects\storage\saver\image_save.py", line 49, in fetch
response = session.request(method=method,url=url,headers=headers,params=params,timeout=timeout,verify=False)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 257, in request
self.perform_request(method, url, *args, **kwargs)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 190, in perform_request
return super(CloudScraper, self).request(method, url, *args, **kwargs)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 398, in connect
context.verify_mode = resolve_cert_reqs(self.cert_reqs)
File "C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 738, in verify_mode
super(SSLContext, SSLContext).verify_mode.__set__(self, value)
ValueError: Cannot set verify_mode to CERT_NONE when check_hostname is enabled.
代码
import cloudscraper
from urllib.parse import urlparse
session = cloudscraper.CloudScraper(
browser={
'browser': 'chrome',
'platform': 'windows',
'mobile': False
},)
def fetch(url : str , method : str = "GET",refer : str = None,params : dict = {},
timeout : int = 40) -> bytes:
url_r = urlparse(url)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'referer': refer if refer else "%s://%s/"%(url_r.scheme,url_r.netloc)}
try:
response = session.request(method=method,url=url,headers=headers,params=params,timeout=timeout,verify=False)
return response.content
except Exception as e: print(e) ```
1条答案
按热度按时间vyswwuz21#
我可以用这个来解