Skip to content

Instantly share code, notes, and snippets.

@markmc
Created July 11, 2013 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markmc/5973868 to your computer and use it in GitHub Desktop.
Save markmc/5973868 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