SSL connection issue with Windows CPython

Blairo blair.bethwaite at gmail.com
Sun Dec 4 18:10:53 EST 2011


Hi all,

I've written a Python API for the Windows Azure Service Management web-
service. Requests against the web-service are HTTPS with a client
certificate used for authentication. This works fine with CPython
(tested with 2.6 and 2.7) on Linux, but something is amiss with the
SSL connection with vanilla python.org CPython (again 2.6 and 2.7) on
Windows. I've managed to boil it down to a simple test case, which
should return a list of Azure data-centre locations (requires an Azure
account):
--------------------
Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit
(AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> sub_id = '506...-...-...-...-...'
>>> cert = 'c:\\users\\blair\\...\\azure.pem'
>>> import socket,ssl
>>> s = ssl.wrap_socket(socket.socket(), certfile=cert)
>>> s.connect(('management.core.windows.net',443))
>>> s.send("GET /%s/locations HTTP/1.1\r\nAccept-Encoding: identity\r\nX-Ms-Version: 2011-10-01\r\nHost: management.core.windows.net\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n" % sub_id)
202
>>> s.read(2048)

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    s.read(2048)
  File "C:\Python27\lib\ssl.py", line 138, in read
    return self._sslobj.read(len)
error: [Errno 10054] An existing connection was forcibly closed by the
remote host
--------------------

What's interesting is that the exact same code works with ActivePython
(2.6 and 2.7), output omitted here for brevity. There is more detail
on a (currently unanswered) stackoverflow post:
http://stackoverflow.com/questions/8342714/python-https-against-azure-service-management-api-fails-on-windows
.

I'm not sure where/what the difference is. My best guess so far is
that ActivePython bundles a newer version of OpenSSL then the
python.org version and that the problem must be there. Any further
insight would be appreciated.

TIA,
~Blair



More information about the Python-list mailing list