Define a timeout for all http requests

This commit is contained in:
Némunaire 2012-07-27 18:18:13 +02:00
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: