Problem with ssl in Python 2.5
September 2017
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.
Recent Entries
Recent Comments
Recent Trackbacks
OpenBSD (9 items)
BSD (0 items)
FreeBSD (19 items)
Linux (3 items)
Security (3 items)
Python (22 items)
Zope (13 items)
Daily (144 items)
e-shell (9 items)
Hacks (14 items)
PostgreSQL (3 items)
OSX (8 items)
Nintendo DS (0 items)
enlightenment (0 items)
Apache (3 items)
Nintendo Wii (1 items)
Django (24 items)
Music (12 items)
Plone (7 items)
Varnish (0 items)
Lugo (2 items)
Sendmail (0 items)
europython (7 items)
Cherokee (1 items)
self (1 items)
Nature (1 items)
Hiking (0 items)
uwsgi (0 items)
nginx (0 items)
cycling (9 items)
Networking (1 items)
DNS (0 items)

Syndicate this site (XML)

RSS/RDF 0.91

13 junio

Problem with ssl in Python 2.5

macports, macports, macports... WTF

I'm beginning to think about the posibility that installing Python from MacPorts in Leopard, and forgetting about the default version that comes with the operating system is not a good idea.

Seems like the guy behind the python25 port decided to split some of the builtin modules into separate ports (I'm not going to explain my oppinion about splitting things into small packages here :D) and today I found that SSL socket support is one of those separate packages.

I was working on a module to add support for sending data by mail from a webapp I've created on top of Django. I followed all the steps in the official docs, so I added some lines into my project

# SMTP Settings

As I've set EMAIL_USE_TLS to True, the django internals code that will send the email for me will try to use a secure TLS link to send the email to the server.

I saved the settings and tried my code, just to notice an ugly message:

'module' object has no attribute 'ssl'

more precisely:

File "/opt/local/lib/python2.5/site-packages/django/core/handlers/" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/opt/local/lib/python2.5/site-packages/django/contrib/auth/" in __call__
  67.             return self.view_func(request, *args, **kwargs)
File "/Users/wu/codigo23/devel_python/Beyle/FMJJ/../FMJJ/beyle/" in enviar_por_mail
  2009.         email_obj.send()
File "/opt/local/lib/python2.5/site-packages/django/core/" in send
  259.         return self.get_connection(fail_silently).send_messages([self])
File "/opt/local/lib/python2.5/site-packages/django/core/" in send_messages
  162.         new_conn_created =
File "/opt/local/lib/python2.5/site-packages/django/core/" in open
  130.                 self.connection.starttls()
File "/opt/local/lib/python2.5/" in starttls
  605.             sslobj = socket.ssl(self.sock, keyfile, certfile)

Exception Type: AttributeError at /beyle/obra/2873/mail/
Exception Value: 'module' object has no attribute 'ssl'

mmm... mumble, mumble (as old mickey mouse should say)

What happened here? it seems like Python wasn't able to connect using the secure link... Let's test if there is any problem with that...

Python comes by default with a set of testing scripts you can use to (know what?) test some functionalities. one of those test scripts is, which seemed perfect for do what I needed. But... wait a second... seems like that file doesn't exist in my Python installation:

snowball:~ wu$ ls -l /opt/local/lib/python2.5/test/
ls: /opt/local/lib/python2.5/test/ No such file or directory
snowball:~ wu$

Only then, I began to think about the posibility of a separated port, so I took a look over the MacPorts database, just to find...

snowball:~ wu$ port search py|grep ssl
py-openssl                     python/py-openssl 0.6          python wrapper around the OpenSSL library
py-pow                         python/py-pow  0.7          Python OpenSSL Wrappers is an interface to the openssl library
py25-socket-ssl                python/py25-socket-ssl 2.5.2        Python secure sockets via OpenSSL
py30-socket-ssl                python/py30-socket-ssl 3.0a3        Python secure sockets via OpenSSL
snowball:~ wu$

There it was! a py25-socket-ssl port. I proceeded installing it:

sudo port -v install py25-socket-ssl

And everything works fine since then. Take care, as some other interesting/important modules (like the new native SQLite support) are in separate ports too. You can get a list of python25 related ports with:

port search py25

And remember, once you find an unusual error, just think about a separate port.

Posted by wu at 19:13 | Comments (0) | Trackbacks (0)
<< COREBlog and pygments | Main | Classic photographies (lego style) >>
Re: Problem with ssl in Python 2.5

On my system the file is called ...

Posted by: betabug at junio 14,2008 18:56
Re: Problem with ssl in Python 2.5

Thanks brother. Got me sorted in no time (added readline support too).

[New OSX user, migrated from Debian]

Posted by: Darryl Cousins at agosto 05,2008 12:54
Re: Problem with ssl in Python 2.5

Glad to hear it has been helpful for someone. (darryl, do you have a blog or something?)

Posted by: Wu at agosto 06,2008 01:45
Please send trackback to:
There are no trackbacks.
Post a comment