- 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)
- 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: ...