Python Scraping Data From the Web Introducing Data Scraping Beautiful Soup

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,810 Points

[SOLVED] Any ideas on why I'm getting this error and failure to compile?

Well, only the third video... and I broke it. :(

Any ideas?

/Users/ja/PycharmProjects/web_scraping/venv/bin/python /Users/ja/PycharmProjects/web_scraping/scraper.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1240, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1083, in request
    self._send_request(method, url, body, headers)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1079, in endheaders
    self._send_output(message_body)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 911, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 854, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1237, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 376, in wrap_socket
    _context=self)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 747, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 983, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 628, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ja/PycharmProjects/web_scraping/scraper.py", line 4, in <module>
    html = urlopen('https://treehouse-projects.github.io/horse-land/index.html')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 465, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 483, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 443, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1283, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1242, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)>

Process finished with exit code 1

I'm still relatively new to Python and PyCharm, so I'm kind of at a loss now for troubleshooting.

Thanks in advance! :dizzy:

5 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,810 Points

Well,

After banging my head against the wall a few times, I finally noticed that PyCharm interpreter was, for reasons I'm not sure, using Python 3.5.1. This version will throw that error because of the deprecated use by Apple of OpenSSL.
This is, however, now included in the latest version of Python (3.7) and is why the code runs once this was changed.
I am running on a Mac

Once I went to the Applications and found the Python 3.7 folder, I just double-clicked the Update Shell Command file and like magic, everything now seems to work just like Ken's :smile:

I need a Tylenol now! Lol

Hope this helps someone else down the road! :) :dizzy:

olu adesina
olu adesina
Pro Student 19,018 Points

I don't know where I am going, I cannot find the Update Shell Command - I am currently using a Mac - could you explain where you went exactly?

Jason Anders
Jason Anders
Treehouse Moderator 144,810 Points

olu adesina

Once you download Python 3.7, there should be a "Python 3.7" folder in your Root Application folder in Finder. Inside that folder there is the Update Shell Command command file that you just double click on.

:dizzy:

Ross Coe
Ross Coe
5,060 Points

I had this but changed the projects interpretor to be the system one (maybe there was python3 and update command in venv?) https://www.jetbrains.com/help/pycharm-edu/configuring-available-python-interpreters.html

Mirza Gogic
Mirza Gogic
2,735 Points

On your Mac, if you're using it, go to Applications, Python 3.7 and then double-click "Install Certificates.command". That should do it.

P.S. Don't forget to install a parser. For some reason, hmtl-parser didn't work for me, so I used "lxml" instead. Worked like a charm.