[tools/web] Add header param to getContentUrl()
Add the possibility to specify headers when querying websites.
This commit is contained in:
parent
684806baaf
commit
c55e66dd70
@ -60,7 +60,7 @@ def getPassword(url):
|
||||
|
||||
# Get real pages
|
||||
|
||||
def getURLContent(url, body=None, timeout=7):
|
||||
def getURLContent(url, body=None, timeout=7, header=None):
|
||||
"""Return page content corresponding to URL or None if any error occurs
|
||||
|
||||
Arguments:
|
||||
@ -97,19 +97,24 @@ def getURLContent(url, body=None, timeout=7):
|
||||
else:
|
||||
raise IRCException("Invalid URL")
|
||||
|
||||
from nemubot import __version__
|
||||
if header is None:
|
||||
header = {"User-agent": "Nemubot v%s" % __version__}
|
||||
elif "User-agent" not in header:
|
||||
header["User-agent"] = "Nemubot v%s" % __version__
|
||||
|
||||
import socket
|
||||
try:
|
||||
from nemubot import __version__
|
||||
if o.query != '':
|
||||
conn.request("GET" if body is None else "POST",
|
||||
o.path + "?" + o.query,
|
||||
body,
|
||||
{"User-agent": "Nemubot v%s" % __version__})
|
||||
header)
|
||||
else:
|
||||
conn.request("GET" if body is None else "POST",
|
||||
o.path,
|
||||
body,
|
||||
{"User-agent": "Nemubot v%s" % __version__})
|
||||
header)
|
||||
except OSError as e:
|
||||
raise IRCException(e.strerror)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user