0

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.

asked Dec 15, 2015 at 16:26
5
  • 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 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? Commented Jan 14, 2016 at 16:19
  • @Jacobm001 Python 2.7.9 Commented Feb 4, 2016 at 19:54

3 Answers 3

2

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

answered Jan 30, 2016 at 2:28
1
  • 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? Commented Feb 4, 2016 at 17:49
1

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.

answered Feb 5, 2016 at 2:51
0

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.

answered Jan 24, 2016 at 6:10
1
  • I am using python 2.7.9 Commented Feb 4, 2016 at 19:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.