scripts: python3: fix urllib imports

Some functions and classes have been moved from urllib[2]
to urllib.request and urllib.error in python 3.

Used new imports to make the code working in python 3.

(From OE-Core rev: ec3f1759e8b491a44a1fc1ecb6f89919dd30da97)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2016-06-02 13:12:50 +03:00 committed by Richard Purdie
parent ee31bad762
commit f6f10858e5
2 changed files with 9 additions and 9 deletions

View File

@ -7,7 +7,7 @@
import sys import sys
import os import os
import subprocess import subprocess
import urllib2 import urllib.request
# Allow importing scripts/lib modules # Allow importing scripts/lib modules
@ -47,7 +47,7 @@ def verifyHomepage(bbhandler):
homepage = data.getVar("HOMEPAGE", True) homepage = data.getVar("HOMEPAGE", True)
if homepage: if homepage:
try: try:
urllib2.urlopen(homepage, timeout=5) urllib.request.urlopen(homepage, timeout=5)
except Exception: except Exception:
count = count + wgetHomepage(os.path.basename(realfn), homepage) count = count + wgetHomepage(os.path.basename(realfn), homepage)
checked.append(realfn) checked.append(realfn)

View File

@ -7,7 +7,7 @@
# Author: Andreea Proca <andreea.b.proca@intel.com> # Author: Andreea Proca <andreea.b.proca@intel.com>
# Author: Michael Wood <michael.g.wood@intel.com> # Author: Michael Wood <michael.g.wood@intel.com>
import urllib2 import urllib.request, urllib.error
import sys import sys
import json import json
import os import os
@ -25,10 +25,10 @@ log = logging.getLogger("send-error-report")
logging.basicConfig(format='%(levelname)s: %(message)s') logging.basicConfig(format='%(levelname)s: %(message)s')
def getPayloadLimit(url): def getPayloadLimit(url):
req = urllib2.Request(url, None) req = urllib.request.Request(url, None)
try: try:
response = urllib2.urlopen(req) response = urllib.request.urlopen(req)
except urllib2.URLError as e: except urllib.error.URLError as e:
# Use this opportunity to bail out if we can't even contact the server # Use this opportunity to bail out if we can't even contact the server
log.error("Could not contact server: " + url) log.error("Could not contact server: " + url)
log.error(e.reason) log.error(e.reason)
@ -136,10 +136,10 @@ def send_data(data, args):
else: else:
url = "http://"+args.server+"/ClientPost/" url = "http://"+args.server+"/ClientPost/"
req = urllib2.Request(url, data=data, headers=headers) req = urllib.request.Request(url, data=data, headers=headers)
try: try:
response = urllib2.urlopen(req) response = urllib.request.urlopen(req)
except urllib2.HTTPError, e: except urllib.error.HTTPError as e:
logging.error(e.reason) logging.error(e.reason)
sys.exit(1) sys.exit(1)