Community Training Classes & Labs > F5 Programmability Training Index

Lab A.6: Create a Python Script

In this lab we will use the ‘Generate Code’ feature of Postman to create a python script from a collection of requests.

Task 1 – Create a simple script

Note

Remember to have the correct environment selected in Postman

Perform the following steps to complete this task:

  1. Expand the ‘Lab 5.6 – Create a Python Script’ folder in the Postman collection

  2. Click the ‘Step 1 – Create a HTTP Monitor’ item in the collection

  3. Click the ‘Code’ link in the Postman window:

    image73

  4. Select Python -> Requests from the menu on the top right of the window:

    image74

  5. Examine the Python code that was generated. Click the ‘Copy to Clipboard’ button

  6. Open a new text file and paste the generated code. We need to modify the line that sends the request to DISABLE SSL certificate verification. Find the following line:

    response = requests.request("POST", url, data=payload, headers=headers)
    

    And add a verify=False option to it:

    response = requests.request("POST", url, data=payload, headers=headers, verify=False)
    

    Save the file on your Desktop as lab5_6.py

  7. Open a command prompt and run the script by typing python lab5_6.py:

    image75

  8. Verify the monitor was created on BIG-IP

  9. Delete the monitor to prepare for the next task

Task 2 – Chain together multiple requests

In this task we will repeat the process from Task 1 to chain together multiple requests.

Perform the following steps:

  1. Repeat the procedure from Task 1 with each of the items in the ‘Lab 5.6’ postman collection. Append each snippet of code to your existing script until you have all 5 requests in the script. You will need to remove the duplicate ‘import requests’ lines and update each request with the ‘verify=False’ option.
  2. Save the file
  3. Run the script and verify the config was created.