Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol

5,125 views
Skip to first unread message

Piyush Verma

unread,
Dec 15, 2017, 2:07:14 PM12/15/17
to
Getting SSL error while connecting from httplib.HTTPSConnection.

Any help would be appreciated.

self.connection.request(method, request, payload, self.headers)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1053, in request
self._send_request(method, url, body, headers)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1093, in _send_request
self.endheaders(body)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1049, in endheaders
self._send_output(message_body)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 893, in _send_output
self.send(msg)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 855, in send
self.connect()
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1274, in connect
server_hostname=server_hostname)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
line 352, in wrap_socket
_context=self)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
line 579, in __init__
self.do_handshake()
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
line 808, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)

Regards,
~Piyush
Facebook <https://www.facebook.com/piyushkv1> Twitter
<https://twitter.com/SocializePiyush>

Piyush Verma

unread,
Dec 15, 2017, 4:15:56 PM12/15/17
to

dieter

unread,
Dec 16, 2017, 3:30:29 AM12/16/17
to
Piyush Verma <114p...@gmail.com> writes:

> Getting SSL error while connecting from httplib.HTTPSConnection.
>
> Any help would be appreciated.
> ...
> line 579, in __init__
> self.do_handshake()
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
> line 808, in do_handshake
> self._sslobj.do_handshake()
> ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)

Are you sure, you try to connect to an HTTPS port?

The error message tells you that the "ssl" handshake failed because
the protocol was unknown (likely because the message was not understood).
The most natural reason is to try to connect to something which is not
prepared for an "ssl" handshake.

dieter

unread,
Dec 16, 2017, 3:43:59 PM12/16/17
to

Piyush Verma

unread,
Dec 17, 2017, 2:28:52 PM12/17/17
to
Yes Dieter, I see that it is connecting with 443 port number and service is
running. Is this related to python version or mac?
> --
> https://mail.python.org/mailman/listinfo/python-list
>

dieter

unread,
Dec 17, 2017, 4:00:32 PM12/17/17
to
Piyush Verma <114p...@gmail.com> writes:

> Yes Dieter, I see that it is connecting with 443 port number and service is
> running. Is this related to python version or mac?

It might be.

Python does not perform the SSL handling itself but delegates it to
an external SSL library ("OpenSSL" on a *nix like platform).
SSL can use different protocols, e.g. for the encryption.
The error message might mean that the server side uses a protocol
which is not supported by the client side. In this case, you would need
to use a more up-to-date SSL library.


I have had no problems to acces "https://www.facebook.com/piyushkv1"
with "urllib2.urlopen" of Python 2.7.12 (on Ubuntu 16.4).

Chris Angelico

unread,
Dec 17, 2017, 4:19:29 PM12/17/17
to
On Mon, Dec 18, 2017 at 6:28 AM, Piyush Verma <114p...@gmail.com> wrote:
> Yes Dieter, I see that it is connecting with 443 port number and service is
> running. Is this related to python version or mac?

Can you confirm that it really is an HTTPS server, not just an HTTP
server that's running on port 443? Try accessing it using a web
browser or some other program.

ChrisA

Piyush Verma

unread,
Dec 18, 2017, 4:59:46 AM12/18/17
to
Hi Chris, Yes it is HTTPS server. I was debugging and found some relevant
data which may help to identify the problem.

In my Mac OS, I have two version of openssl version installed. default was
/usr/bin/openssl, which i changed to brew installed one.
(virtenv) $ /usr/bin/openssl version
OpenSSL 0.9.8zh 14 Jan 2016
(virtenv) $ openssl version
OpenSSL 1.0.2n 7 Dec 2017

In my python code when I printed the ssl version, python still taking the
system installed ssl version in my Mac OS. I think same problem in my code,
how can I make python to understand to take latest ssl?
import ssl
ssl.OPENSSL_VERSION
'OpenSSL 0.9.8zh 14 Jan 2016'
> --
> https://mail.python.org/mailman/listinfo/python-list
>
0 new messages