code: def check_httpretty_authfail404(exp_called, d):
      # mimic behavior of nersc which 404s but provides feedback whenever
      # credentials are incorrect.  In our case we should fail properly
      credential = FakeCredential1(name="test", url=None)
  
      was_called = []
  
      def request_post_callback(request, uri, headers):
          post_params = request.parsed_body
          if post_params["password"][0] == "testpassword2":
              was_called.append("404")
              return 404, headers, "Really 404"
          else:
              was_called.append("failed")
              return 404, headers, "Failed"
  
      httpretty.register_uri(
          httpretty.POST, url, body=request_post_callback
      )
  
      # Also we want to test how would it work if cookie is available (may be)
      authenticator = HTMLFormAuthenticator(
          dict(
              username="{user}",
              password="{password}",
              submit="CustomLogin",
          ),
          failure_re="Failed",
      )
  
      downloader = HTTPDownloader(
          credential=credential, authenticator=authenticator
      )
      # first one goes with regular DownloadError -- was 404 with not matching content
      assert_raises(DownloadError, downloader.download, url, path=d)
      assert_equal(was_called, exp_called)
  
imports: import builtins
  import os
  import re
  import time
  from calendar import timegm
  from os.path import join
  from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import download_url, get_url_straight_filename
  from datalad.utils import ensure_unicode
  from ...support.exceptions import AccessFailedError
  from ..base import BaseDownloader, DownloadError, IncompleteDownloadError, NoneAuthenticator
  from ..credentials import LORIS_Token, Token, UserPassword
  from ..http import HTMLFormAuthenticator, HTTPBaseAuthenticator, HTTPBearerTokenAuthenticator, HTTPDownloader, process_www_authenticate
  from unittest.mock import patch
  from ...support.exceptions import AccessDeniedError, AnonymousAccessDeniedError
  from ...support.network import get_url_disposition_filename
  from ...support.status import FileStatus
  from ...tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_greater, assert_in, assert_not_in, assert_raises, known_failure_githubci_win, ok_file_has_content, serve_path_via_http, skip_if, skip_if_no_network, swallow_logs, swallow_outputs, use_cassette, with_fake_cookies_db, with_memory_keyring, with_tempfile, with_testsui, with_tree, without_http_proxy
  from ...utils import read_file
label_desc: Use image node_id 19 for calling a global function with example usage: check_httpretty_authfail404(exp_called, d) and returns: int,  headers,  str, int,  headers,  str