Skip to content

Instantly share code, notes, and snippets.

@nickmbailey
Created January 7, 2014 20:23
Show Gist options
  • Select an option

  • Save nickmbailey/8306249 to your computer and use it in GitHub Desktop.

Select an option

Save nickmbailey/8306249 to your computer and use it in GitHub Desktop.
[Nicks-MacBook-Pro:14:22:15] opscenterd$ python test.py
Unable to verify ssl certificate.
Received response
200
[Nicks-MacBook-Pro:14:22:52] opscenterd$
from twisted.internet import reactor, ssl
from twisted.web.client import Agent
from OpenSSL import SSL
def ssl_simple_verifyCB(conn, x509, errnum, errdepth, ok):
if not ok:
print "Unable to verify ssl certificate."
return ok
class CtxFactory(ssl.ClientContextFactory):
def getContext(self, *args, **kwargs):
self.method = SSL.SSLv23_METHOD
ctx = ssl.ClientContextFactory.getContext(self)
ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, ssl_simple_verifyCB)
return ctx
def display(response):
print "Received response"
print response.code
def main():
agent = Agent(reactor, CtxFactory())
d = agent.request("GET", "https://twistedmatrix.com/trac/")
d.addCallback(display)
d.addCallback(lambda ignored: reactor.stop())
reactor.run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment