Ubuntu – How to add SSL support to Python

pythonssl

On Ubuntu 14.04, I installed Python 3. Now that I am programming with it, I had a problem with Python and I am told that the error occurred because I did not install Python with SSL support.

Is it possible to add SSL support to Python without needing to uninstall and reinstall Python from the start?

I ask this question following the comment on my question here.

Best Answer

Python3 in Ubuntu has SSL support. You can simply test by running python3 and then firing of a couple of commands:

import urllib.request
urllib.request.urlopen('https://askubuntu.com').read()

A ton of HTML will fall out the other side. SSL is working.

As a more general answer to your SO question, I'd strongly consider looking at the requests library. It can be installed with the python3-requests package and makes all the stuff you're doing much easier and more logical. Boils your entire thing down to:

import requests
requests.post(
    url,
    auth=requests.auth.HTTPBasicAuth('user', 'pass'),
    data={"Hello": "There"},
    headers={'content-type': 'application/x-www-form-urlencoded'}
)

I agree that it's largely preference (you can do everything you want without it) but it makes for easier to understand code.