@@ -132,22 +132,27 @@ def discoverEndpoint(url, test_urls=True):
132132
133133 # status, webmention
134134 href = None
135- r = requests .get (url ,verify = False )
136- if r .status_code == requests .codes .ok :
137- try :
138- link = parse_link_header (r .headers ['link' ])
139- href = link .get ('webmention' , '' ) or link .get ('http://webmention.org' , '' ) or link .get ('http://webmention.org/' , '' ) or link .get ('https://webmention.org' , '' ) or link .get ('https://webmention.org/' , '' )
140-
141- # force searching in the HTML if not found
142- if not href :
143- raise AttributeError
144- except (KeyError , AttributeError ):
145- href = findEndpoint (r .text )
146-
147- if href is not None :
148- href = urljoin (url , href )
149-
150- return (r .status_code , href )
135+ try :
136+ r = requests .get (url , verify = False )
137+ rc = r .status_code
138+ if rc == requests .codes .ok :
139+ try :
140+ link = parse_link_header (r .headers ['link' ])
141+ href = link .get ('webmention' , '' ) or link .get ('http://webmention.org' , '' ) or link .get ('http://webmention.org/' , '' ) or link .get ('https://webmention.org' , '' ) or link .get ('https://webmention.org/' , '' )
142+
143+ # force searching in the HTML if not found
144+ if not href :
145+ raise AttributeError
146+ except (KeyError , AttributeError ):
147+ href = findEndpoint (r .text )
148+
149+ if href is not None :
150+ href = urljoin (url , href )
151+ except (requests .exceptions .RequestException , requests .exceptions .ConnectionError ,
152+ requests .exceptions .HTTPError , requests .exceptions .URLRequired ,
153+ requests .exceptions .TooManyRedirects , requests .exceptions .Timeout ):
154+ rc = 500
155+ return (rc , href )
151156
152157
153158def sendWebmention (sourceURL , targetURL , webmention = None , test_urls = True , vouchDomain = None ):
0 commit comments