Created
January 7, 2014 20:23
-
-
Save nickmbailey/8306249 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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