Add a fallback user agent
This commit is contained in:
1 parent
5a903ce0bf
commit
d36b236070
1 file changed
+16
-9
@@ -548,15 +548,22 @@ class Twitch:
|
|||||||
if session.closed:
|
if session.closed:
|
||||||
raise RuntimeError("Session is closed")
|
raise RuntimeError("Session is closed")
|
||||||
return session
|
return session
|
||||||
# obtain the latest Chrome user agent from a Github project
|
# try to obtain the latest Chrome user agent from a Github project
|
||||||
async with aiohttp.request(
|
try:
|
||||||
"GET", "https://jnrbsn.github.io/user-agents/user-agents.json"
|
async with aiohttp.request(
|
||||||
) as response:
|
"GET", "https://jnrbsn.github.io/user-agents/user-agents.json"
|
||||||
agents = await response.json()
|
) as response:
|
||||||
if sys.platform == "win32":
|
agents = await response.json()
|
||||||
chrome_agent = random.choice(agents[:3])
|
if sys.platform == "win32":
|
||||||
elif sys.platform == "linux":
|
chrome_agent = random.choice(agents[:3])
|
||||||
chrome_agent = random.choice(agents[7:11])
|
elif sys.platform == "linux":
|
||||||
|
chrome_agent = random.choice(agents[7:11])
|
||||||
|
except Exception:
|
||||||
|
# looks like we can't rely on 3rd parties too much
|
||||||
|
chrome_agent = (
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
|
||||||
|
)
|
||||||
# load in cookies
|
# load in cookies
|
||||||
cookie_jar = aiohttp.CookieJar()
|
cookie_jar = aiohttp.CookieJar()
|
||||||
if COOKIES_PATH.exists():
|
if COOKIES_PATH.exists():
|
||||||
|
|||||||
Reference in new issue
Block a user