Fix urllib import issue for Python2/3 compatible code.
Story: 2003429 Task: 24620 Change-Id: If45a091b0b5e3aa7597457a0c56dc46a3432312a Signed-off-by: chenyan <yan.chen@intel.com> Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
parent
a539b771cf
commit
7777f0a7f4
|
@ -1215,7 +1215,12 @@ def check_for_os_region_name():
|
||||||
auth_token, endpoint = get_auth_token_and_endpoint(region)
|
auth_token, endpoint = get_auth_token_and_endpoint(region)
|
||||||
if endpoint is not None:
|
if endpoint is not None:
|
||||||
global api_addr
|
global api_addr
|
||||||
from urlparse import urlparse
|
try:
|
||||||
|
# python 2
|
||||||
|
from urlparse import urlparse
|
||||||
|
except ImportError:
|
||||||
|
# python 3
|
||||||
|
from urllib.parse import urlparse
|
||||||
url = urlparse(endpoint)
|
url = urlparse(endpoint)
|
||||||
address = format_url_address(url.hostname)
|
address = format_url_address(url.hostname)
|
||||||
api_addr = '{}:{}'.format(address, url.port)
|
api_addr = '{}:{}'.format(address, url.port)
|
||||||
|
|
|
@ -5,11 +5,18 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import getopt
|
import getopt
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Python 2
|
||||||
|
from urllib import urlencode
|
||||||
|
from urllib2 import urlopen
|
||||||
|
except ImportError:
|
||||||
|
# Python 3
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
opts = ['sw_version=', 'prefix=']
|
opts = ['sw_version=', 'prefix=']
|
||||||
|
|
||||||
|
@ -24,8 +31,8 @@ def request_patch_id(sw_version="1.01", prefix="CGCS"):
|
||||||
print("raw_parms = %s" % str(raw_parms))
|
print("raw_parms = %s" % str(raw_parms))
|
||||||
|
|
||||||
url = "http://%s:%d/get_patch_id" % (server, port)
|
url = "http://%s:%d/get_patch_id" % (server, port)
|
||||||
params = urllib.urlencode(raw_parms)
|
params = urlencode(raw_parms)
|
||||||
response = urllib2.urlopen(url, params).read()
|
response = urlopen(url, params).read()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue