0

This simple code in Python displays Ascii art and is taken from the following quora response: https://qr.ae/TWNB4S. I have Python version 3.7.3 installed on my Windows 10 laptop via independent installer from python.org and also via anaconda suite. The code runs fine on Jupyter notebook launched via anaconda. But when I run the same code via pycharm IDE I get SSL related errors.

I searched online for this Error but could not find a way to resolve this on my Windows 10 python 3.7.3 installation. But it works fine on my Anaconda python 3.7.3 version. So is there a way to overcome this Error? Code:

import ascii
output =  ascii.loadFromUrl("https://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1F43200000578-0-image-a-17_1441127603656.jpg")
print(output)

The Errors when I run the above code via Pycharm IDE:

Traceback (most recent call last):
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 350, in connect
    ssl_context=context)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 853, in _create
    self.do_handshake()
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
***ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)***

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/billn/Google Drive/Books/UDEMY - Complete Python 3 Bootcamp - Jose Portilla/gg.py", line 3, in <module>
    output = ascii.loadFromUrl("https://i.dailymail.co.uk/i/pix/2015/09/01/18/2BE1F43200000578-0-image-a-17_1441127603656.jpg")
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\ascii\__init__.py", line 17, in loadFromUrl
    fd = http.request('GET', URL)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\request.py", line 68, in request
    **urlopen_kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\request.py", line 89, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\poolmanager.py", line 326, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
    **response_kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
    **response_kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
    **response_kw)
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\billn\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='i.dailymail.co.uk', port=443): Max retries exceeded with url: /i/pix/2015/09/01/18/2BE1F43200000578-0-image-a-17_1441127603656.jpg (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
pchegoor
  • 386
  • 1
  • 5
  • 14

1 Answers1

0

If you haven't already, you can try installing the certifi package from pip. Otherwise, there are a number of solutions here, some of which cover how to make sure you have your certificates installed and others which show how to disable certificate verification.