diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-09-08 10:50:23 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-09-08 10:50:23 +0200 |
commit | 3506f60953b737fce23e251b596b9d75b7a82679 (patch) | |
tree | 49263b2bbe5b46a4943d5d7c8a40aaf9db010285 /source/utils.py | |
parent | Improvement to the CSS for the navigation container. (diff) | |
download | newspipe-3506f60953b737fce23e251b596b9d75b7a82679.tar.gz newspipe-3506f60953b737fce23e251b596b9d75b7a82679.tar.bz2 newspipe-3506f60953b737fce23e251b596b9d75b7a82679.zip |
detect_url_erros() now uses the proxy.
Diffstat (limited to 'source/utils.py')
-rwxr-xr-x | source/utils.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/source/utils.py b/source/utils.py index aaaa558c..173b08cd 100755 --- a/source/utils.py +++ b/source/utils.py @@ -86,17 +86,26 @@ def detect_url_errors(list_of_urls): Return a list of error(s). """ errors = [] + if conf.HTTP_PROXY == "": + proxy = {} + else: + proxy = {"http" : conf.HTTP_PROXY} + opener = urllib.request.FancyURLopener(proxy) for url in list_of_urls: - req = urllib.request.Request(url) try: - urllib.request.urlopen(req) + opener = urllib.request.build_opener() + opener.addheaders = [('User-agent', conf.USER_AGENT)] + opener.open(url) except urllib.error.HTTPError as e: # server couldn't fulfill the request errors.append((url, e.code, \ http.server.BaseHTTPRequestHandler.responses[e.code][1])) except urllib.error.URLError as e: # failed to reach the server - errors.append((url, e.reason.errno ,e.reason.strerror)) + if type(e.reason) == str: + errors.append((url, e.reason, e.reason)) + else: + errors.append((url, e.reason.errno, e.reason.strerror)) return errors def generate_qr_code(article): |