Keep py3.X compatibility for urllib
urllib/urllib2 is incompatible for python 3 Use modules from six.moves.urllib instead of urllib and urllib2 Change-Id: Ic9d8ce4e700d19053c67cf667e1d802bd1477108 Partial-Bug:#1280105
This commit is contained in:
parent
1c3a82d818
commit
7bd4ebdc38
@ -24,7 +24,9 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
from six.moves.urllib import error as urlerr
|
||||
from six.moves.urllib import request as urlreq
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import glob2
|
||||
@ -52,12 +54,12 @@ def download_listing(dest):
|
||||
'Typos?action=raw')
|
||||
logger.debug("Downloading latest RETF listing from %s into %s.",
|
||||
url, dest)
|
||||
response = urllib2.urlopen(url)
|
||||
response = urlreq.urlopen(url)
|
||||
data = response.read()
|
||||
logger.info("Downloading latest RETF listing from %s succeeded.", url)
|
||||
except urllib2.HTTPError as ex:
|
||||
except urlerr.HTTPError as ex:
|
||||
raise DownloadRetfListingFailed(six.text_type(ex))
|
||||
except urllib2.URLError as ex:
|
||||
except urlerr.URLError as ex:
|
||||
raise DownloadRetfListingFailed(six.text_type(ex))
|
||||
|
||||
try:
|
||||
|
@ -36,15 +36,12 @@ import operator
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import six
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
if six.PY3:
|
||||
from urllib import request as urllib2
|
||||
else:
|
||||
import urllib2
|
||||
from six.moves.urllib import error as urlerr
|
||||
from six.moves.urllib import request as urlreq
|
||||
|
||||
from lxml import etree
|
||||
from oslo_config import cfg
|
||||
@ -307,8 +304,8 @@ def verify_valid_links(doc):
|
||||
continue
|
||||
|
||||
try:
|
||||
urllib2.urlopen(url)
|
||||
except urllib2.HTTPError as e:
|
||||
urlreq.urlopen(url)
|
||||
except urlerr.HTTPError as e:
|
||||
# Ignore some error codes:
|
||||
# 403 (Forbidden) since it often means that the user-agent
|
||||
# is wrong.
|
||||
@ -317,7 +314,7 @@ def verify_valid_links(doc):
|
||||
e_line = node.sourceline
|
||||
msg.append("URL %s not reachable at line %d, error %s" % (
|
||||
url, e_line, e))
|
||||
except urllib2.URLError as e:
|
||||
except urlerr.URLError as e:
|
||||
e_line = node.sourceline
|
||||
msg.append("URL %s invalid at line %d, error %s" % (
|
||||
url, e_line, e))
|
||||
|
Loading…
Reference in New Issue
Block a user