mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 20:22:45 +01:00
userAgents: avoid potential IndexError
random.choice() should only be run after verifying the config has been set.
This commit is contained in:
parent
4c4d0024ca
commit
5315cd3275
@ -1331,8 +1331,8 @@ def defaultHttpHeaders(network, channel):
|
|||||||
try:
|
try:
|
||||||
language = supybot.protocols.http.requestLanguage.getSpecific(
|
language = supybot.protocols.http.requestLanguage.getSpecific(
|
||||||
network, channel)()
|
network, channel)()
|
||||||
agent = random.choice(supybot.protocols.http.userAgents.getSpecific(
|
agent = supybot.protocols.http.userAgents.getSpecific(
|
||||||
network, channel)())
|
network, channel)()
|
||||||
except registry.NonExistentRegistryEntry:
|
except registry.NonExistentRegistryEntry:
|
||||||
pass # Starting up; headers will be set by HttpRequestLanguage/UserAgents later
|
pass # Starting up; headers will be set by HttpRequestLanguage/UserAgents later
|
||||||
else:
|
else:
|
||||||
@ -1340,7 +1340,9 @@ def defaultHttpHeaders(network, channel):
|
|||||||
headers['Accept-Language'] = language
|
headers['Accept-Language'] = language
|
||||||
elif 'Accept-Language' in headers:
|
elif 'Accept-Language' in headers:
|
||||||
del headers['Accept-Language']
|
del headers['Accept-Language']
|
||||||
if agent.strip():
|
if agent:
|
||||||
|
agent = random.choice(agent).strip()
|
||||||
|
if agent:
|
||||||
headers['User-agent'] = agent
|
headers['User-agent'] = agent
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user