diff --git a/tools/bootstrap_upip.sh b/tools/bootstrap_upip.sh
index 667d0845a4687ede7e5d6b2d2d8224792e6ce7a4..2891775d7deac8e5c364efdeab4c9a9158c2de3b 100755
--- a/tools/bootstrap_upip.sh
+++ b/tools/bootstrap_upip.sh
@@ -17,7 +17,7 @@ fi
 
 # Remove any stale old version
 rm -rf micropython-upip-*
-wget -nd -r -l1 https://pypi.python.org/pypi/micropython-upip/ --accept-regex ".*pypi.python.org/packages/source/.*.gz" --reject=html
+wget -nd -rH -l1 -D files.pythonhosted.org https://pypi.org/project/micropython-upip/ --reject=html
 
 tar xfz micropython-upip-*.tar.gz
 tmpd="$PWD"
diff --git a/tools/upip.py b/tools/upip.py
index 411da49e8cd8ee7734864504d9a39ab6a4032c73..a400c317438e7135b4d143e04de04abc52efa3d9 100644
--- a/tools/upip.py
+++ b/tools/upip.py
@@ -1,3 +1,10 @@
+#
+# upip - Package manager for MicroPython
+#
+# Copyright (c) 2015-2018 Paul Sokolovsky
+#
+# Licensed under the MIT license.
+#
 import sys
 import gc
 import uos as os
@@ -110,16 +117,16 @@ def url_open(url):
 
     proto, _, host, urlpath = url.split('/', 3)
     try:
-        ai = usocket.getaddrinfo(host, 443)
+        ai = usocket.getaddrinfo(host, 443, 0, usocket.SOCK_STREAM)
     except OSError as e:
         fatal("Unable to resolve %s (no Internet?)" % host, e)
     #print("Address infos:", ai)
-    addr = ai[0][4]
+    ai = ai[0]
 
-    s = usocket.socket(ai[0][0])
+    s = usocket.socket(ai[0], ai[1], ai[2])
     try:
         #print("Connect address:", addr)
-        s.connect(addr)
+        s.connect(ai[-1])
 
         if proto == "https:":
             s = ussl.wrap_socket(s, server_hostname=host)
@@ -149,7 +156,7 @@ def url_open(url):
 
 
 def get_pkg_metadata(name):
-    f = url_open("https://pypi.python.org/pypi/%s/json" % name)
+    f = url_open("https://pypi.org/pypi/%s/json" % name)
     try:
         return json.load(f)
     finally: