changeset 26:adb79e44323a

switch to 'requests' lib to fix SSL errors Ignore-this: 749393b44686715dc27b2c9bb8717e82
author drewp@bigasterisk.com
date Sat, 24 Dec 2016 20:18:45 -0800
parents e02fc021ab89
children 3d9dc1571ade
files pagetitle.py
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pagetitle.py	Tue May 24 23:06:52 2016 -0700
+++ b/pagetitle.py	Sat Dec 24 20:18:45 2016 -0800
@@ -1,7 +1,8 @@
 import lxml.html.soupparser
 import datetime, socket
 from dateutil.tz import tzlocal
-import restkit
+import requests
+import traceback
 
 class CantGetTitle(ValueError):
     pass
@@ -12,19 +13,20 @@
 
     def getPageTitleNow(self, uri):
         try:
-            response = restkit.request(uri, timeout=1, follow_redirect=True,
+            response = requests.get(uri, timeout=1, allow_redirects=True,
                                 headers={
                                     'user-agent':
                                     'link title checker - drewp@bigasterisk.com'
                                 })
-            if not response.status.startswith('2'):
-                raise CantGetTitle("(got %s)" % response.status)
+            if not str(response.status_code).startswith('2'):
+                raise CantGetTitle("(got %s)" % response.status_code)
             root = lxml.html.soupparser.fromstring(
-                response.body_string())
+                response.text)
 
             for title in root.cssselect("title"):
                 return title.text
-        except restkit.RequestError:
+        except Exception:
+            traceback.print_exc()
             raise CantGetTitle("(error requesting title from site)")
             
     def pageTitle(self, uri):