Define a timeout for all http requests
This commit is contained in:
parent
6d26a13752
commit
a2b273d09b
13 changed files with 12 additions and 12 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue