How to do it...

  1. Import the urllib components that are required. We'll be making URL requests, and building more complex objects, such as query strings. We'll need the urllib.request and urllib.parse modules for these two features. Since the expected response is in JSON, then the json module will be useful as well:
        import urllib.request 
        import urllib.parse 
        import json 
  1. Define the query string that will be used. In this case, all of the values happen to be fixed. In a more complex application, some might be fixed and some might be based on user inputs:
        query = {'hand': 5} 
  1. Use the query to build the pieces of the full URL:

 full_url = urllib.parse.ParseResult( scheme="http", netloc="127.0.0.1:5000", path="/dealer" + "/hand/", params=None, ...

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.