Skip to content

Commit

Permalink
PR #353 for issue #352 - adding WWW-LINK Resource error and title mis…
Browse files Browse the repository at this point in the history
…sing

* #352 fixes adding WWW-LINK Resource error and title missing

* #352 fixes adding WWW-LINK Resource error and title missing - flake8
  • Loading branch information
justb4 committed Apr 26, 2021
1 parent b229528 commit be792d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.git

14 changes: 8 additions & 6 deletions GeoHealthCheck/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,16 @@ def sniff_test_resource(config, resource_type, url):
raise ValueError(message)

if resource_type == 'WWW:LINK':
content_type = ows.info().getheader('Content-Type')
content_type = ows.info().get('Content-Type')

# Check content if the response is not an image
# When response is not an image try parse out Title and
# any Exceptions
if 'image/' not in content_type:
content = ows.read()
import re
try:
title_re = re.compile("<title>(.+?)</title>")
title = title_re.search(content).group(1)
title_re = re.compile('<title>(.+?)</title>'.encode())
title = title_re.search(content).group(1).decode()
except Exception:
title = url

Expand All @@ -200,8 +201,9 @@ def sniff_test_resource(config, resource_type, url):
exception_text = None
try:
except_re = re.compile(
"ServiceException>|ExceptionReport>")
exception_text = except_re.search(content).group(0)
'ServiceException>|ExceptionReport>'.encode())
exception_text = except_re.search(content).\
group(0).decode()
except Exception:
# No Exception in Response text
pass
Expand Down

0 comments on commit be792d8

Please sign in to comment.