This commit is contained in:
Oliver Freund 2023-12-06 13:57:40 +01:00 committed by GitHub
commit 65b8a48a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

1
news/11577.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Improve error message when using non-local file URIs

View File

@ -1,5 +1,7 @@
import os
import re
import string
import sys
import urllib.parse
import urllib.request
from typing import Optional
@ -40,8 +42,15 @@ def url_to_path(url: str) -> str:
# If we have a UNC path, prepend UNC share notation.
netloc = "\\\\" + netloc
else:
# do not include traceback as the error message should be self-explaining
sys.tracebacklimit = 0
# suggest using 'file:/' to the user:
suggestion = re.sub("(^file:)(/)+", "file:/", url)
raise ValueError(
f"non-local file URIs are not supported on this platform: {url!r}"
f"{url!r} points to the domain '{netloc}'. "
f"Non-local file URIs are not supported on this platform. "
f"Did you mean to use '{suggestion}'?"
)
path = urllib.request.url2pathname(netloc + path)