I was running “Upgrade Network” on the WordPress Multisite installation that I use to develop client sites and for experimenting with themes and code. The main site has the Query Monitor plugin active. I noticed some errors being mentioned in the admin bar but the page refreshed before I could read them. I managed to take a quick screenshot before the next 5 sites were processed.
I password protect the development site because it was hacked last year. It has basic http authentication but this seems to have done the job. When I saw the 401 error I knew that the password protection was the issue.
I searched the WordPress code for the step=upgrade_db text and found it in wp-admin/network/upgrade.php and saw that the wp_remote_get() function was being called. This lead me to the WP_Http class and to the ‘http_request_args‘ filter (Edit: D’oh – I should have seen all that from the screenshot but old habits of searching source code are hard to break).
A quick Google search (“wordpress wp_http password authentication”) led me to Basic Authentication with the WordPress HTTP API that demonstrated how to add username and password to a WP_Http instance.
After a quick experiment that the chosen filter (‘http_request_args‘) was right, I included the username and password and reran “Upgrade Network.” This time it ran without any errors.
I love it when a small bit of code can achieve so much!