9
$\begingroup$

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 as URLRead.

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

$\endgroup$
1
  • 1
    $\begingroup$ Interestingly enough, there is a symbol URLUtilities`PackageScope`$options, setting which with association <|Interactive -> False|> works for URLRead (you can call it without parameters now and it won't show a dialog), but it doesn't for URLDownload $\endgroup$
    – Stitch
    Commented Apr 12, 2017 at 15:43

1 Answer 1

4
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.