acloud: fix py3 compatible issue: AttributeError: 'HTTPMessage' object has no attribute 'getheaders'
use six.moves.urllib and use get() instead.
and fix ModuleNotFoundError of No module named 'urllib2'
Replace urllib2 as six.moves.urllib() would work both py2 and py3.
BUG: 137195528
BUG: 144327414
Test: acloud-dev setup --force -vv
Change-Id: I4d8c66980cdb6e0037ec5d3dbe44cf8eab06990a
diff --git a/setup/google_sdk.py b/setup/google_sdk.py
index 78afd78..925b772 100644
--- a/setup/google_sdk.py
+++ b/setup/google_sdk.py
@@ -34,7 +34,7 @@
import shutil
import sys
import tempfile
-import urllib2
+from six.moves import urllib
from acloud import errors
from acloud.internal.lib import utils
@@ -165,9 +165,9 @@
file_path = os.path.join(self._tmp_path, filename)
logger.info("Download file from: %s", url)
logger.info("Save the file to: %s", file_path)
- url_stream = urllib2.urlopen(url)
+ url_stream = urllib.request.urlopen(url)
metadata = url_stream.info()
- file_size = int(metadata.getheaders("Content-Length")[0])
+ file_size = int(metadata.get("Content-Length"))
logger.info("Downloading google SDK: %s bytes.", file_size)
with open(file_path, 'wb') as output:
output.write(url_stream.read())