- 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
- 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}
- 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, ...