campaignmonitor / createsend-python

A Python library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-python
MIT License
57 stars 64 forks source link

Added SSL certificate validation if https API is used #14

Closed shennys closed 11 years ago

jdennes commented 11 years ago

I wanted to write some tests for this new functionality, so I went to test it first using the contents of the master branch:

$ cat example.py 
from createsend import *
cs = CreateSend({'api_key': 'my api key'})
clients = cs.clients()
$ python --version
Python 2.7.3
$ python example.py 
Traceback (most recent call last):
  File "example.py", line 3, in <module>
    clients = cs.clients()
  File "/Users/jdennes/projects/campaignmonitor/createsend-python/createsend/createsend.py", line 245, in clients
    response = self._get('/clients.json')
  File "/Users/jdennes/projects/campaignmonitor/createsend-python/createsend/createsend.py", line 208, in _get
    return self.make_request(path=path, method="GET", params=params, username=username, password=password)
  File "/Users/jdennes/projects/campaignmonitor/createsend-python/createsend/createsend.py", line 163, in make_request
    sslsock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs='cacert.pem')     
  File "/opt/boxen/homebrew/Cellar/python/2.7.3-boxen2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/opt/boxen/homebrew/Cellar/python/2.7.3-boxen2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 141, in __init__
    ciphers)
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

@shennys @richardbremner Is there something I'm missing, or is this just broken? How did you test this before merging?

shennys commented 11 years ago

The change was tested using a script in the same directory as the createsend.py module, so it was definitely an oversight on our part that it wasn't tested using a script in a different location. I've made the change in createsend.py so that an absolute path is specified for the cacert.pem file and tested it works for a script that imports the createsend module from a different directory. See pull request: https://github.com/campaignmonitor/createsend-python/pull/16

jdennes commented 11 years ago

This is fixed properly in 9b7aa952.