From 78f1f68a98c53043eb017dfa67831b125cf5208e Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 29 Mar 2016 16:21:27 +0100 Subject: [PATCH] made it possible to get http code even when a HTTPError kicks up. --- Utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Utils.py b/Utils.py index 00c2699b..175c3ac7 100644 --- a/Utils.py +++ b/Utils.py @@ -1,4 +1,4 @@ -import json, re, traceback, urllib.request, urllib.parse +import json, re, traceback, urllib.request, urllib.parse, urllib.error import bs4 USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 " @@ -47,9 +47,12 @@ def get_url(url, **kwargs): try: response = urllib.request.urlopen(request) - except: + except urllib.error.HTTPError as e: traceback.print_exc() - return False + if kwargs.get("code"): + return e.code, False + else: + return False response_content = response.read() encoding = response.info().get_content_charset()