mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Don't urllib.unquote when using requests (#2943)
This commit is contained in:
parent
fe5ba1cce7
commit
fd685f29fe
1 changed files with 6 additions and 9 deletions
|
@ -911,21 +911,18 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
|
|
||||||
def _retrieveURL(self, url: str) -> str | None:
|
def _retrieveURL(self, url: str) -> str | None:
|
||||||
"Download file into media folder and return local filename or None."
|
"Download file into media folder and return local filename or None."
|
||||||
# urllib doesn't understand percent-escaped utf8, but requires things like
|
local = url.lower().startswith("file://")
|
||||||
# '#' to be escaped.
|
|
||||||
url = urllib.parse.unquote(url)
|
|
||||||
if url.lower().startswith("file://"):
|
|
||||||
url = url.replace("%", "%25")
|
|
||||||
url = url.replace("#", "%23")
|
|
||||||
local = True
|
|
||||||
else:
|
|
||||||
local = False
|
|
||||||
# fetch it into a temporary folder
|
# fetch it into a temporary folder
|
||||||
self.mw.progress.start(immediate=not local, parent=self.parentWindow)
|
self.mw.progress.start(immediate=not local, parent=self.parentWindow)
|
||||||
content_type = None
|
content_type = None
|
||||||
error_msg: str | None = None
|
error_msg: str | None = None
|
||||||
try:
|
try:
|
||||||
if local:
|
if local:
|
||||||
|
# urllib doesn't understand percent-escaped utf8, but requires things like
|
||||||
|
# '#' to be escaped.
|
||||||
|
url = urllib.parse.unquote(url)
|
||||||
|
url = url.replace("%", "%25")
|
||||||
|
url = url.replace("#", "%23")
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url, None, {"User-Agent": "Mozilla/5.0 (compatible; Anki)"}
|
url, None, {"User-Agent": "Mozilla/5.0 (compatible; Anki)"}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue