I followed the instructions on Adafruit's Website to no avail. The Python script keeps spitting out a ton of errors:
Press Ctrl-C to quit.
Traceback (most recent call last):
File "checkmail.py", line 53, in <module>
loop()
File "checkmail.py", line 26, in loop
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
File "/usr/local/lib/python2.7/dist-packages/imapclient/imapclient.py", line 152, in __init__
self._imap = self._create_IMAP4()
File "/usr/local/lib/python2.7/dist-packages/imapclient/imapclient.py", line 164, in _create_IMAP4
self._timeout)
File "/usr/local/lib/python2.7/dist-packages/imapclient/tls.py", line 153, in __init__
imaplib.IMAP4.__init__(self, host, port)
File "/usr/lib/python2.7/imaplib.py", line 172, in __init__
self.open(host, port)
File "/usr/local/lib/python2.7/dist-packages/imapclient/tls.py", line 159, in open
self.sock = wrap_socket(sock, self.ssl_context, host)
File "/usr/local/lib/python2.7/dist-packages/imapclient/tls.py", line 126, in wrap_socket
ssl_context = create_default_context()
File "/usr/local/lib/python2.7/dist-packages/imapclient/tls.py", line 65, in create_default_context
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
AttributeError: 'module' object has no attribute 'SSLContext'
Any help is greatly appreciated :). Thank you in advance.
3 Answers 3
I ran into the same issue with the "Jessie" build and python 2.7.9 on my model B Pi. I had to remove most of the built in python packages, remove the dist files, and then reinstall them - then the script worked.
Don't do this unless you have a good backup of your Pi SD card or you don't mind starting over again:
1) sudo apt-get purge python python-pip libssl-dev libffi-dev python-dev
2) sudo apt-get autoremove
(answer yes)
3) sudo rm -rf /usr/local/lib/python2.7/dist-packages/*
4) sudo apt-get install python-pip libssl-dev libffi-dev python-dev
(this will reinstall python as well)
5) sudo pip install -U setuptools
(they might already be there)
6) sudo pip install imapclient
(this should take a few minutes)
The default build on my Pi was missing about 15 packages under /usr/local/lib/python2.7/dist-packages
but it wouldn't install them even when forced by a pip
install. Removing all of it and installing it again populated more packages, including a newer version of imapclient.
Your Pi will still have Python version 2.7.9 installed once you are finished, so nothing appears to have changed that much beyond more packages where you need them.
This applies to the adafruit mail notifier script here, which is what the original post referred to:
https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds/python-script
-
When trying to reinstall python I get this error: E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?Yllier123– Yllier1232016年02月04日 17:49:15 +00:00Commented Feb 4, 2016 at 17:49
I figured this out. For anyone else having this problem, here is how to solve it: This error is caused by the absence of libssl-dev
. For those who can't download it:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip libssl-dev libffi-dev python-dev
sudo pip install -U setup tools
sudo pip install imapclient
I've found that by removing some of the python packages it causes a problem with the desktop environment.
The minimum version that supports that attribute is Python 2.7.9. Make sure you're using Python 2.7.9 or above.
Most Linux distributions (including Raspbian) use Python 2.6.something.
-
I am using python 2.7.9Yllier123– Yllier1232016年02月04日 19:47:46 +00:00Commented Feb 4, 2016 at 19:47
python --version
?