3
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'

The code was run according to the documentation on https://pypi.org/project/cloudscraper/ and I cant find relevant supporting information on how to solve this error message.

Rivered
  • 741
  • 7
  • 27
  • 1
    Make sure that the following packages are up to date: `Requests >= 2.9.2` `Requests_toolbelt >= 0.9.1` as described here https://pypi.org/project/cloudscraper/ under the dependencies heading. I hope this helps! – Eiri Mar 21 '22 at 13:48
  • @Eiri, Unfortunately, updating the packages had no positive effect, the same error message prevails. – Rivered Mar 21 '22 at 21:21
  • Can you please try using *python3.7*? – Eiri Mar 22 '22 at 13:03
  • 1
    @Eiri, sadly somehow my pipenv fails with python3.7. But got the same error on python 3.6 and working well on python3.8. – Ikar Pohorský Mar 24 '22 at 09:41
  • I can confirm python 3.8 works, bypassing cloudflare :) – Rivered Mar 24 '22 at 21:48
  • Any way to fix the code to be compatible with python 3.6 or lower? I am too unfamiliar with the architecture there – Rivered Mar 24 '22 at 22:24

1 Answers1

8

My scripts is working well until the latest version 1.2.60 release 12 days ago. Maybe is the problem with the old library ssl.py in python3.6.

Here are my temporally solution:

  • use the last version 1.2.58: pip3 install cloudscraper==1.2.58
  • or using python 3.7+, tested working with python 3.7
ben_29
  • 96
  • 2