gpt4 book ai didi

python - Cloudscraper 返回 AttributeError : 'SSLContext' object has no attribute 'orig_wrap_socket'

转载 作者:行者123 更新时间:2023-12-04 22:36:05 25 4
gpt4 key购买 nike

import cloudscraper
import requests

scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
# Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
print (scraper.get("https://www.youtube.com/").text )

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-459-1f19dc044105> in <module>
2 import requests
3
----> 4 scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
5 # Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
6 print (scraper.get("https://www.youtube.com/").text )

~/.local/lib/python3.6/site-packages/cloudscraper/__init__.py in create_scraper(cls, sess, **kwargs)
315 Convenience function for creating a ready-to-go CloudScraper object.
316
--> 317 scraper = cls(**kwargs)
318
319 if sess:

~/.local/lib/python3.6/site-packages/cloudscraper/__init__.py in __init__(self, *args, **kwargs)
169 server_hostname=self.server_hostname,
170 source_address=self.source_address,
--> 171 ssl_context=self.ssl_context
172 )
173 )

~/.local/lib/python3.6/site-packages/cloudscraper/__init__.py in __init__(self, *args, **kwargs)
75 self.ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
76
---> 77 self.ssl_context.orig_wrap_socket = self.ssl_context.wrap_socket
78 self.ssl_context.wrap_socket = self.wrap_socket
79

AttributeError: 'SSLContext' object has no attribute 'orig_wrap_socket'

代码是根据 https://pypi.org/project/cloudscraper/ 上的文档运行的我找不到有关如何解决此错误消息的相关支持信息。

最佳答案

我的脚本运行良好,直到 12 天前发布了最新版本 1.2.60。可能是python3.6中旧库ssl.py的问题。

这是我暂时的解决方案:

  • 使用最新版本1.2.58:pip3 install cloudscraper==1.2.58
  • 或使用python 3.7+,测试使用python 3.7

关于python - Cloudscraper 返回 AttributeError : 'SSLContext' object has no attribute 'orig_wrap_socket' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71548899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com