Creating an example client

  1. Create an SSL context that will work with a self-signed certificate:
        import ssl 
        context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) 
        context.check_hostname = False 
        context.verify_mode = ssl.CERT_NONE 

This context can be used with all urllib requests. This will politely ignore the lack of CA signature on the certificate.


Here's how we use this context to fetch the Swagger specification:


        with urllib.request.urlopen(swagger_request, context=context) as response: 
            swagger = json.loads(response.read().decode("utf-8")) 
            pprint(swagger) 
  1. Create the URL for creating a new player instance. Note that we must use https for the scheme. We've built a ParseResult object to show the various pieces of the URL separately: ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.