switch to requests for HTTP queries

This commit is contained in:
mutantmonkey
2013-06-08 22:27:24 -07:00
parent 259c222623
commit 5cb88f3cf8
23 changed files with 131 additions and 161 deletions

View File

@@ -8,20 +8,19 @@ http://inamidst.com/phenny/
"""
import re
import urllib.request
#import urllib.request
import urllib.parse
import urllib.error
import http.client
import http.cookiejar
#import http.client
#import http.cookiejar
import time
from html.entities import name2codepoint
import web
from tools import deprecated
from modules.linx import get_title as linx_gettitle
cj = http.cookiejar.LWPCookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
#cj = http.cookiejar.LWPCookieJar()
#opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
#urllib.request.install_opener(opener)
def head(phenny, input):
@@ -47,11 +46,9 @@ def head(phenny, input):
try:
info = web.head(uri)
info['status'] = '200'
except urllib.error.HTTPError as e:
except web.HTTPError as e:
return phenny.say(str(e.code))
except http.client.InvalidURL:
return phenny.say("Not a valid URI, sorry.")
except IOError:
except web.ConnectionError:
return phenny.say("Can't connect to %s" % uri)
resptime = time.time() - start
@@ -159,7 +156,7 @@ def gettitle(phenny, uri):
#bytes = u.read(262144)
#u.close()
except IOError:
except web.ConnectionError:
return
m = r_title.search(bytes)