From dfd23f6a41aa82815e724807bfc2e9850f7585f4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 19 Sep 2018 23:49:56 +1000 Subject: [PATCH] use anki requests client for common user agent name some websites are blocking access from the generic requests UA - now they can choose whether they wish to block Anki or not --- aqt/editor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aqt/editor.py b/aqt/editor.py index b84de6ec2..6353a6a55 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -25,6 +25,7 @@ from aqt.utils import shortcut, showInfo, showWarning, getFile, \ import aqt from bs4 import BeautifulSoup import requests +from anki.sync import AnkiRequestsClient pics = ("jpg", "jpeg", "png", "tif", "tiff", "gif", "svg", "webp") audio = ("wav", "mp3", "ogg", "flac", "mp4", "swf", "mov", "mpeg", "mkv", "m4a", "3gp", "spx", "oga", "webm") @@ -658,7 +659,9 @@ to a cloze type first, via Edit>Change Note Type.""")) 'User-Agent': 'Mozilla/5.0 (compatible; Anki)'}) filecontents = urllib.request.urlopen(req).read() else: - r = requests.get(url, timeout=30) + reqs = AnkiRequestsClient() + reqs.timeout = 30 + r = reqs.get(url) if r.status_code != 200: showWarning(_("Unexpected response code: %s") % r.status_code) return