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>
  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
  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.

  • It is actually only one error the last line is the error. Is your system up do date? run sudo apt-get update && sudo apt-get upgrade. Also, what distro are you using and which version? Commented Dec 15, 2015 at 16:45
  • @SteveRobillard Running Raspbian. Currently updating it
    – Yllier123
    Commented Dec 15, 2015 at 18:38
  • I think I know what the problem is I am not sure there is a fix - other than switching to Jessie. Can you also add to your question (after the update) the output of python at the command line. Ctrl-d will close the propmt that the command opens Commented Dec 15, 2015 at 18:40
  • I'm betting you don't have a new enough version of python. What is the output of python --version?
    – Jacobm001
    Commented Jan 14, 2016 at 16:19
  • @Jacobm001 Python 2.7.9
    – Yllier123
    Commented Feb 4, 2016 at 19:54

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:


  • 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
    Commented 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:

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install python-pip libssl-dev libffi-dev python-dev
  4. sudo pip install -U setup tools
  5. 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.9
    – Yllier123
    Commented Feb 4, 2016 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.