Skip to content

Commit 9b73217

Browse files
committed
networking-py: use DNS hostname in urllib_get.py
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 1f5eff9 commit 9b73217

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

examples/networking-py/urllib_get.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
"""High-level HTTP GET using urllib (Python stdlib).
22
33
Demonstrates that Python's standard urllib.request module works
4-
over the host-proxied socket layer — no raw sockets needed.
5-
6-
Uses a raw IP with Host header to avoid DNS dependency (glibc's
7-
getaddrinfo doesn't yet work over host-proxied UDP sockets).
4+
over the host-proxied socket layer with full DNS resolution.
85
"""
96
import urllib.request
107
import sys
118

12-
URL = "http://172.66.147.243/"
9+
URL = "http://example.com/"
1310

1411
print(f"Fetching {URL} ...")
15-
req = urllib.request.Request(URL, headers={"Host": "example.com"})
1612
try:
17-
with urllib.request.urlopen(req, timeout=10) as resp:
13+
with urllib.request.urlopen(URL, timeout=10) as resp:
1814
body = resp.read().decode("utf-8", errors="replace")
1915
print(f"Status: {resp.status}")
2016
print(f"Body length: {len(body)} bytes")

0 commit comments

Comments
 (0)