File: consumer

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (21 lines) | stat: -rwxr-xr-x 454 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /usr/bin/env python3

import sys
from socket import timeout
import urllib.request

if len(sys.argv) > 1:
  url = sys.argv[1]
else:
  url = 'http://www.ubuntu.com'

try:
  response = urllib.request.urlopen(url, timeout=3)
  decoded_response = response.read().decode('utf-8')
  print(decoded_response, end="")
except urllib.error.URLError as e:
  print("Error, reason: ", e.reason)
  sys.exit(1)
except timeout:
  print("request timeout")
  sys.exit(1)