Report HTTP error to users
This commit is contained in:
parent
4cbf73c45a
commit
d83b0d1b81
1 changed files with 3 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ from urllib.parse import quote
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
from exception import IRCException
|
||||||
import xmlparser
|
import xmlparser
|
||||||
|
|
||||||
def isURL(url):
|
def isURL(url):
|
||||||
|
|
@ -108,7 +109,7 @@ def getURLContent(url, timeout=15):
|
||||||
else:
|
else:
|
||||||
charset = cha[0]
|
charset = cha[0]
|
||||||
except http.client.BadStatusLine:
|
except http.client.BadStatusLine:
|
||||||
return None
|
raise IRCException("Invalid HTTP response")
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
@ -117,7 +118,7 @@ def getURLContent(url, timeout=15):
|
||||||
elif (res.status == http.client.FOUND or res.status == http.client.MOVED_PERMANENTLY) and res.getheader("Location") != url:
|
elif (res.status == http.client.FOUND or res.status == http.client.MOVED_PERMANENTLY) and res.getheader("Location") != url:
|
||||||
return getURLContent(res.getheader("Location"), timeout)
|
return getURLContent(res.getheader("Location"), timeout)
|
||||||
else:
|
else:
|
||||||
return None
|
raise IRCException("A HTTP error occurs: %d - %s" % (res.status, http.client.responses[res.status]))
|
||||||
|
|
||||||
def getXML(url, timeout=15):
|
def getXML(url, timeout=15):
|
||||||
"""Get content page and return XML parsed content"""
|
"""Get content page and return XML parsed content"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue