Bug introduced in 11.0 and persists through 11.3
The original problem is was fixed in V11.2 but since then it returns File[path/to/file/that/does/not/exits]
instead of 401
Failure/HTTPResponse like URLRead
does.
CASE:3877019 - confirmed
The second one prompts the dialog:
URLRead["https://httpbin.org/status/401", Interactive -> False]
URLDownload["https://httpbin.org/status/401", Interactive -> False]
but both should return 401 HTTPResponse since
ref/URLDownload:
URLDownload
takes the options asURLRead
.ref/URLRead
Interactive
-True
- whether to allow interactive authentication dialogs
Have I missed something? Is there a workaround?
It probably can be narrowed to URLSave
broken for "DisplayProxyDialog" -> False
, but this is undocumented so I can't complain.
related:
How to omit the authentification dialog during URLRead?
Inconsistent Authorization Dialog (401) handling
Answer
Before it is fixed one can use this quick workaround based on How to get StatusCode without fetching Body/Content in the background:
DialoglessURLDownload = URLFetch[
#, "StatusCode", Method -> "HEAD", "DisplayProxyDialog" -> False
] /. (200 :> URLDownload[##]) &
I've decided I will return the status code for any case that isn't 200
, that is arguable but URLDownload
itself gives non existing File[...]
when it fails so I will not try to mimic wrong behavior. This at least gives you a possibility to react appropriately.
DialoglessURLDownload @ "https://httpbin.org/status/401"
401
Comments
Post a Comment