-
-
Save kod3r/5976378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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