def validate_URL_existence(self, url, use_session=False):
"""
tries to validate existence of given url by trying to open it.
true if HTTP OK, false if HTTP NOT FOUND otherwise
raises error containing error code and message
arguments:
url -- the url link to open and validate
use_session -- if True then this uses self.session.get(url) instead
of urlopen(url) to get response
returns
true if http response OK 200
false if http response NOT FOUND 404
"""
if use_session:
response = self.session.get(url)
if response.status_code == httplib.OK:
return True
elif response.status_code == httplib.NOT_FOUND:
return False
else:
raise Exception(
str(response.status_code) + " " + response.reason)
else:
response = urlopen(url, timeout=self.max_wait_time)
if response.code == httplib.OK:
return True
elif response.code == httplib.NOT_FOUND:
return False
else:
raise Exception(str(response.code) + " " + response.msg)
评论列表
文章目录