switch to requests for HTTP queries
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user