I'm getting a "WindowsError: [Error 5] Access is denied" message when reading a website with urllib2.
from urllib2 import urlopen, Request
from bs4 import BeautifulSoup
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
req = Request('https://' + url, headers=hdr)
soup = BeautifulSoup( urlopen( req ).read() )
The full traceback is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 449, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1240, in https_open
context=self._context)
File "C:\Python27\lib\urllib2.py", line 1166, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
File "C:\Python27\lib\httplib.py", line 1258, in __init__
context = ssl._create_default_https_context()
File "C:\Python27\lib\ssl.py", line 440, in create_default_context
context.load_default_certs(purpose)
File "C:\Python27\lib\ssl.py", line 391, in load_default_certs
self._load_windows_store_certs(storename, purpose)
File "C:\Python27\lib\ssl.py", line 378, in _load_windows_store_certs
for cert, encoding, trust in enum_certificates(storename):
WindowsError: [Error 5] Access is denied
I've tried running the script from a command prompt with admin privileges, as suggested here, but it does not fix the problem.
Any suggestions on how to resolve this error?