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:
parent
8f05db5981
commit
dfd23f6a41
@ -25,6 +25,7 @@ from aqt.utils import shortcut, showInfo, showWarning, getFile, \
|
|||||||
import aqt
|
import aqt
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests
|
import requests
|
||||||
|
from anki.sync import AnkiRequestsClient
|
||||||
|
|
||||||
pics = ("jpg", "jpeg", "png", "tif", "tiff", "gif", "svg", "webp")
|
pics = ("jpg", "jpeg", "png", "tif", "tiff", "gif", "svg", "webp")
|
||||||
audio = ("wav", "mp3", "ogg", "flac", "mp4", "swf", "mov", "mpeg", "mkv", "m4a", "3gp", "spx", "oga", "webm")
|
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)'})
|
'User-Agent': 'Mozilla/5.0 (compatible; Anki)'})
|
||||||
filecontents = urllib.request.urlopen(req).read()
|
filecontents = urllib.request.urlopen(req).read()
|
||||||
else:
|
else:
|
||||||
r = requests.get(url, timeout=30)
|
reqs = AnkiRequestsClient()
|
||||||
|
reqs.timeout = 30
|
||||||
|
r = reqs.get(url)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
showWarning(_("Unexpected response code: %s") % r.status_code)
|
showWarning(_("Unexpected response code: %s") % r.status_code)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user