Define a timeout for all http requests

This commit is contained in:
Némunaire 2012-07-27 18:18:13 +02:00
parent 6d26a13752
commit a2b273d09b
13 changed files with 12 additions and 12 deletions

View File

@ -61,7 +61,7 @@ def striphtml(data):
return p.sub('', data).replace("(", "/(").replace(")", ")/").replace(""", "\"")
def getPage(terms):
conn = http.client.HTTPConnection("api.duckduckgo.com")
conn = http.client.HTTPConnection("api.duckduckgo.com", timeout=5)
try:
conn.request("GET", "/?q=%s&format=xml" % quote(terms))
except socket.gaierror:

View File

@ -78,7 +78,7 @@ class WFASearch:
def getPage(terms):
conn = http.client.HTTPConnection("api.wolframalpha.com")
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=5)
try:
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
except socket.gaierror:

View File

@ -45,7 +45,7 @@ def striplink(data):
return s.replace("'''", "*")
def getPage(terms, lang):
conn = http.client.HTTPConnection(lang + ".wikipedia.org")
conn = http.client.HTTPConnection(lang + ".wikipedia.org", timeout=5)
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"})
except socket.gaierror:

View File

@ -56,7 +56,7 @@ class Question:
return User(self.node["writer"])
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:
conn.request("GET", "report.php?id=" + hashlib.md5(self.id.encode()).hexdigest() + "&raison=" + quote(raison))
except socket.gaierror:

View File

@ -31,6 +31,7 @@ class GameUpdater(threading.Thread):
quest = 9
else:
if LASTQUESTION >= len(QUESTIONS):
print (QUESTIONS)
random.shuffle(QUESTIONS)
LASTQUESTION = 0
quest = LASTQUESTION

View File

@ -222,4 +222,3 @@ def parselisten (msg):
gu.start()
return True
return False

View File

@ -132,7 +132,7 @@ def startSoutenance (msg):
def getPage():
conn = http.client.HTTPConnection(CONF.getNode("server")["ip"])
conn = http.client.HTTPConnection(CONF.getNode("server")["ip"], timeout=10)
try:
conn.request("GET", CONF.getNode("server")["url"])

View File

@ -38,7 +38,7 @@ def parseanswer(msg):
def getPage(terms):
conn = http.client.HTTPConnection("www.crisco.unicaen.fr")
conn = http.client.HTTPConnection("www.crisco.unicaen.fr", timeout=5)
try:
conn.request("GET", "/des/synonymes/%s" % quote(terms))
except socket.gaierror:

View File

@ -55,7 +55,7 @@ def parseanswer(msg):
def getPage(terms, langfrom="fr", langto="en"):
conn = http.client.HTTPConnection("api.wordreference.com")
conn = http.client.HTTPConnection("api.wordreference.com", timeout=5)
try:
conn.request("GET", "/0.8/%s/json/%s%s/%s" % (CONF.getNode("wrapi")["key"], langfrom, langto, quote(terms)))
except socket.gaierror:

View File

@ -22,7 +22,7 @@ def help_full ():
def getPage (s, p):
conn = http.client.HTTPConnection(s)
conn = http.client.HTTPConnection(s, timeout=10)
try:
conn.request("GET", p)
except socket.gaierror:

View File

@ -116,7 +116,7 @@ class Site:
def getPage(s, p):
conn = http.client.HTTPConnection(s)
conn = http.client.HTTPConnection(s, timeout=10)
try:
conn.request("GET", p)

View File

@ -23,7 +23,7 @@ class Tinyfier(threading.Thread):
self.msg.send_chn("La situation est embarassante, il semblerait que YCC soit down :(")
def getPage(s, p):
conn = http.client.HTTPConnection(s)
conn = http.client.HTTPConnection(s, timeout=10)
try:
conn.request("GET", p)
except socket.gaierror:

View File

@ -38,7 +38,7 @@ def parselisten (msg):
if res is not None:
#print ("seen : %s"%res.group(1))
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.getresponse()
conn.close()