Hands-on Lab·Python Automation for IT
Python urllib Without requests
Sometimes you cannot add a dependency: a locked-down host, a minimal image, a bootstrap script that has to run before pip exists. `urllib.request` does everything the last five guides did, with more code and two behavioural surprises - a 404 raises, and the exception it raises is also a readable response. This guide is the translation, and the honest list of what you give up.
APIs and Cloud Guide 29 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 16 min
- Reviewed24 August 2026
Written against the versions above. `json.loads` accepts `bytes` from Python 3.6. `urllib.request` verifies TLS certificates by default from 3.4.3 onwards - `ssl._create_unverified_context` exists and should not be used.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
Before you start
-
Proving a script needs nothing installed
-
A GET with urlopen
-
Query parameters, and the encoding you now do yourself
-
An error is an exception that is also a response
-
A POST, with headers
-
The Authorization header
-
So wrap it once
-
And what you are not getting