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
This commit is contained in:
Damien Elmes 2018-09-19 23:49:56 +10:00
parent 8f05db5981
commit dfd23f6a41

View File

@ -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