Browse files

Fix TypeError with SSL and no keyfile in Python 3.

  • Loading branch information...
1 parent 6566f3f commit 512337d87ec77ccc84c125d11b05b61d26b12464 @ajdavis ajdavis committed Feb 22, 2014
Showing with 14 additions and 5 deletions.
  1. +14 −5 motor/__init__.py
View
19 motor/__init__.py
@@ -191,11 +191,20 @@ def __init__(
self.use_ssl = use_ssl
self.timeout = None
if self.use_ssl:
- ssl_options = {
- 'certfile': certfile,
- 'keyfile': keyfile,
- 'ca_certs': ca_certs,
- 'cert_reqs': cert_reqs}
+ # In Python 3, Tornado's ssl_options_to_context fails if
+ # any options are None.
+ ssl_options = {}
+ if certfile:
+ ssl_options['certfile'] = certfile
+
+ if keyfile:
+ ssl_options['keyfile'] = keyfile
+
+ if ca_certs:
+ ssl_options['ca_certs'] = ca_certs
+
+ if cert_reqs:
+ ssl_options['cert_reqs'] = cert_reqs
self.stream = iostream.SSLIOStream(
sock, ssl_options=ssl_options, io_loop=io_loop)

0 comments on commit 512337d

Please sign in to comment.