-
download_path.mkdir(parents=True, exist_ok=True)
filename = None
try:
response = self.requests.get(url, stream=True)
if response.status_code == 404:
raise MissingNetworkResourceError(url=url)
elif response.status_code != 200:
raise BadNetworkResourceError(url=url, status_code=response.status_code)
# The initial URL might (read: will) go through URL redirects, so
# we need the *final* response. We look at either the `Content-Disposition`
# header, or the final URL, to extract the cache filename.
cache_full_name = urlparse(response.url).path
header_value = response.headers.get("Content-Disposition")
if header_value:
# See also https://tools.ietf.org/html/rfc6266
value, parameters = parse_header(header_value)
content_type = value.split(":", 1)[-1].strip().lower()
if content_type == "attachment" and parameters.get("filename"):
cache_full_name = parameters["filename"]
cache_name = cache_full_name.split("/")[-1]
filename = download_path / cache_name I'm trying to change the |
Beta Was this translation helpful? Give feedback.
Answered by
mhsmith
Sep 25, 2022
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
DenavDot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
download_path
is aPath
object, so the slash is the equivalent ofos.path.join
.