Skip to content

Instantly share code, notes, and snippets.

@kod3r
Forked from markmc/gist:5973868
Created July 11, 2013 15:17
Show Gist options
  • Save kod3r/5976378 to your computer and use it in GitHub Desktop.
Save kod3r/5976378 to your computer and use it in GitHub Desktop.
import socket
class ImageDownloadFailure(Exception):
def __init__(self, host, port, path, error):
self.host = host
self.port = port
self.path = path
msg = ('Failed to download %(path)s from %(host)s:%(port)s: %(error)s'
% {'host': host, 'port': port, 'path': path, 'error': error})
super(ImageDownloadFailure, self).__init__(msg)
def download_image(host, port, path):
try:
s = socket.create_connection((host, port))
except socket.error as e:
raise ImageDownloadFailure(host, port, path, e.strerror)
download_image('localhost', 3366, 'foobar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment