I was having the same issue when using urllib as the one in the this question but when I changed my code to the code bellow the but when I did i got the error AttributeError: module 'ssl' has no attribute 'PROTOCOL_TLSv1_2'
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import platform
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
my_url = 'https://www....'
uClient = uReq(my_url, context=context)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
print(page_soup.h1)
and from what I read (like this) it was most likely because I was using OpenSSL 0.9.8zh 14 Jan 2016. I tried running
brew uninstall openssl
brew update && brew upgrade && brew cleanup && brew doctor
brew install openssl
to update my ssl to OpenSSL 1.0.2j but I was still getting the same error when I ran my script so I checked openssl version -a
in terminal which was still saying OpenSSL 0.9.8zh 14 Jan 2016
. Some of the other pages I've seen (this one) thought it might be a path issue. In my case running which python
in terminal gave - /usr/local/bin/python where as echo $PATH
returned
/Users/local/.nvm/versions/node/v6.0.0/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
I'm not sure if this path difference is part of the problem but even when I run python2 or python3 in my terminal it again says its using `OpenSSL 0.9.8zh 14 Jan 2016' so it doesn't appear to have updated OpenSSL anywhere. Also I only use python3 so I'm not bothered about wether it has updated for python2. Any solution to my initial problem that would circumvent this issue or a fix for updating my OpenSSL in python3 would be great. (Let me know if there is any other info this question needs).