Define a timeout for all http requests
This commit is contained in:
parent
6d26a13752
commit
a2b273d09b
@ -61,7 +61,7 @@ def striphtml(data):
|
|||||||
return p.sub('', data).replace("(", "/(").replace(")", ")/").replace(""", "\"")
|
return p.sub('', data).replace("(", "/(").replace(")", ")/").replace(""", "\"")
|
||||||
|
|
||||||
def getPage(terms):
|
def getPage(terms):
|
||||||
conn = http.client.HTTPConnection("api.duckduckgo.com")
|
conn = http.client.HTTPConnection("api.duckduckgo.com", timeout=5)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/?q=%s&format=xml" % quote(terms))
|
conn.request("GET", "/?q=%s&format=xml" % quote(terms))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -78,7 +78,7 @@ class WFASearch:
|
|||||||
|
|
||||||
|
|
||||||
def getPage(terms):
|
def getPage(terms):
|
||||||
conn = http.client.HTTPConnection("api.wolframalpha.com")
|
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=5)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
|
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -45,7 +45,7 @@ def striplink(data):
|
|||||||
return s.replace("'''", "*")
|
return s.replace("'''", "*")
|
||||||
|
|
||||||
def getPage(terms, lang):
|
def getPage(terms, lang):
|
||||||
conn = http.client.HTTPConnection(lang + ".wikipedia.org")
|
conn = http.client.HTTPConnection(lang + ".wikipedia.org", timeout=5)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/w/api.php?format=xml&redirects&action=query&prop=revisions&rvprop=content&rvsection=0&titles=%s" % quote(terms), None, {"User-agent": "Nemubot v3"})
|
conn.request("GET", "/w/api.php?format=xml&redirects&action=query&prop=revisions&rvprop=content&rvsection=0&titles=%s" % quote(terms), None, {"User-agent": "Nemubot v3"})
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -56,7 +56,7 @@ class Question:
|
|||||||
return User(self.node["writer"])
|
return User(self.node["writer"])
|
||||||
|
|
||||||
def report(self, raison="Sans raison"):
|
def report(self, raison="Sans raison"):
|
||||||
conn = http.client.HTTPConnection(CONF.getNode("server")["url"])
|
conn = http.client.HTTPConnection(CONF.getNode("server")["url"], timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "report.php?id=" + hashlib.md5(self.id.encode()).hexdigest() + "&raison=" + quote(raison))
|
conn.request("GET", "report.php?id=" + hashlib.md5(self.id.encode()).hexdigest() + "&raison=" + quote(raison))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -31,6 +31,7 @@ class GameUpdater(threading.Thread):
|
|||||||
quest = 9
|
quest = 9
|
||||||
else:
|
else:
|
||||||
if LASTQUESTION >= len(QUESTIONS):
|
if LASTQUESTION >= len(QUESTIONS):
|
||||||
|
print (QUESTIONS)
|
||||||
random.shuffle(QUESTIONS)
|
random.shuffle(QUESTIONS)
|
||||||
LASTQUESTION = 0
|
LASTQUESTION = 0
|
||||||
quest = LASTQUESTION
|
quest = LASTQUESTION
|
||||||
|
@ -222,4 +222,3 @@ def parselisten (msg):
|
|||||||
gu.start()
|
gu.start()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ def startSoutenance (msg):
|
|||||||
|
|
||||||
|
|
||||||
def getPage():
|
def getPage():
|
||||||
conn = http.client.HTTPConnection(CONF.getNode("server")["ip"])
|
conn = http.client.HTTPConnection(CONF.getNode("server")["ip"], timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", CONF.getNode("server")["url"])
|
conn.request("GET", CONF.getNode("server")["url"])
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ def parseanswer(msg):
|
|||||||
|
|
||||||
|
|
||||||
def getPage(terms):
|
def getPage(terms):
|
||||||
conn = http.client.HTTPConnection("www.crisco.unicaen.fr")
|
conn = http.client.HTTPConnection("www.crisco.unicaen.fr", timeout=5)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/des/synonymes/%s" % quote(terms))
|
conn.request("GET", "/des/synonymes/%s" % quote(terms))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -55,7 +55,7 @@ def parseanswer(msg):
|
|||||||
|
|
||||||
|
|
||||||
def getPage(terms, langfrom="fr", langto="en"):
|
def getPage(terms, langfrom="fr", langto="en"):
|
||||||
conn = http.client.HTTPConnection("api.wordreference.com")
|
conn = http.client.HTTPConnection("api.wordreference.com", timeout=5)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/0.8/%s/json/%s%s/%s" % (CONF.getNode("wrapi")["key"], langfrom, langto, quote(terms)))
|
conn.request("GET", "/0.8/%s/json/%s%s/%s" % (CONF.getNode("wrapi")["key"], langfrom, langto, quote(terms)))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -22,7 +22,7 @@ def help_full ():
|
|||||||
|
|
||||||
|
|
||||||
def getPage (s, p):
|
def getPage (s, p):
|
||||||
conn = http.client.HTTPConnection(s)
|
conn = http.client.HTTPConnection(s, timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", p)
|
conn.request("GET", p)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -116,7 +116,7 @@ class Site:
|
|||||||
|
|
||||||
|
|
||||||
def getPage(s, p):
|
def getPage(s, p):
|
||||||
conn = http.client.HTTPConnection(s)
|
conn = http.client.HTTPConnection(s, timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", p)
|
conn.request("GET", p)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Tinyfier(threading.Thread):
|
|||||||
self.msg.send_chn("La situation est embarassante, il semblerait que YCC soit down :(")
|
self.msg.send_chn("La situation est embarassante, il semblerait que YCC soit down :(")
|
||||||
|
|
||||||
def getPage(s, p):
|
def getPage(s, p):
|
||||||
conn = http.client.HTTPConnection(s)
|
conn = http.client.HTTPConnection(s, timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", p)
|
conn.request("GET", p)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -38,7 +38,7 @@ def parselisten (msg):
|
|||||||
if res is not None:
|
if res is not None:
|
||||||
#print ("seen : %s"%res.group(1))
|
#print ("seen : %s"%res.group(1))
|
||||||
URLS[res.group(1)] = msg
|
URLS[res.group(1)] = msg
|
||||||
conn = http.client.HTTPConnection("musik.p0m.fr")
|
conn = http.client.HTTPConnection("musik.p0m.fr", timeout=10)
|
||||||
conn.request("GET", "/?nemubot&a=add&url=%s"%(res.group (1)))
|
conn.request("GET", "/?nemubot&a=add&url=%s"%(res.group (1)))
|
||||||
conn.getresponse()
|
conn.getresponse()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user