diff --git a/upip/upip.py b/upip/upip.py index 5990bca8..7b85c718 100644 --- a/upip/upip.py +++ b/upip/upip.py @@ -117,32 +117,33 @@ def url_open(url): addr = ai[0][4] s = usocket.socket(ai[0][0]) - #print("Connect address:", addr) - s.connect(addr) + try: + #print("Connect address:", addr) + s.connect(addr) - if proto == "https:": - s = ussl.wrap_socket(s) - if warn_ussl: - print("Warning: %s SSL certificate is not validated" % host) - warn_ussl = False + if proto == "https:": + s = ussl.wrap_socket(s) + if warn_ussl: + print("Warning: %s SSL certificate is not validated" % host) + warn_ussl = False - # MicroPython rawsocket module supports file interface directly - s.write("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (urlpath, host)) - l = s.readline() - protover, status, msg = l.split(None, 2) - if status != b"200": - s.close() - exc = ValueError(status) - if status == b"404" or status == b"301": - fatal("Package not found", exc) - fatal("Unexpected error querying for package", exc) - while 1: + # MicroPython rawsocket module supports file interface directly + s.write("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (urlpath, host)) l = s.readline() - if not l: - s.close() - fatal("Unexpected EOF in HTTP headers", ValueError()) - if l == b'\r\n': - break + protover, status, msg = l.split(None, 2) + if status != b"200": + if status == b"404" or status == b"301": + raise NotFoundError("Package not found") + raise ValueError(status) + while 1: + l = s.readline() + if not l: + raise ValueError("Unexpected EOF in HTTP headers") + if l == b'\r\n': + break + except Exception as e: + s.close() + raise e return s @@ -215,9 +216,10 @@ def install(to_install, install_path=None): if deps: deps = deps.decode("utf-8").split("\n") to_install.extend(deps) - except NotFoundError: - print("Error: cannot find '%s' package (or server error), packages may be partially installed" \ - % pkg_spec, file=sys.stderr) + except Exception as e: + print("Error installing '{}': {}, packages may be partially installed".format( + pkg_spec, e), + file=sys.stderr) def get_install_path(): global install_path