Cannot Update Plugins: "Download Failed. Bad Request."
Hello,
I've followed the instructions to the letter, and the JSON info check works.
When I install a test plugin in WP, the newer version (in our repository using your system) is properly detected. But when we attempt to invoke the update, it fails with this error message:
"Download Failed. Bad Request." (or something to that effect).
The attempted download URL is truncated for display (... at the end), but the first portion appears correct.
Any help would be appreciated. This looks like a wonderful system!
Thanks,
Mark
Try downloading the update manually and see what error message (if any) you get.
While the download URL can be truncated in the plugin update log, you can get it another way:
- Install Debug Bar.
- Click the "Debug" link in the admin bar and open the "PUC (your-plugin-slug)" panel.
- You should see a bunch of debugging information about the update checker. Just scroll down to the "Download Url" field.
Hi,
Thanks for the reply. When I download the update manually, the file does download without error.
I am installing the debug components and will let you know those results as soon as I have them. Thanks!
Mark
The "Download URL" in the debug information only shows up as:
http://plugins.mydomain.com/updates/?
(My domain redacted.)
Note: I am using WordPress 3.6 in case it's relevant.
That URL is definitely wrong. There should be at least two parameters after the question mark.
Some ideas:
- Find the "download_url" key in the update JSON. Does it contain the same incorrect URL, or something else?
- The download URL is generated by the
Wpup_UpdateServer::generateDownloadUrl()method inwp-update-server/includes/Wpup/UpdateServer.php. Try adding some diagnostic output to see where it goes wrong, or step through it with a debugger. - Check your PHP error log for messages relating to this library.
Thanks.
The "download_url" key in the JSON is the same incorrect URL:
"download_url":"http://plugins.mydomain.com/updates/?"
There are no PHP error logs at all.
I'll take a look at the code you mentioned which generates the download URL, and add anything else I find.
Thanks!
Mark
Strange, I can't find any reason that the entire URL isn't generated. However I probably don't know a fraction of what you do about how to diagnose and debug it, sorry. :-(
Sorry, I'm not sure what else to do in terms of diagnosing and debugging. Could this be an issue caused by something new in WP 3.6?
Probably not 3.6-related, no. I have a commercial plugin that relies on this library, and it runs fine on my WP 3.6 site.
Did you try adding some debug output to the function I mentioned? Even something as simple as this could help:
protected function generateDownloadUrl(Wpup_Package $package) {
$query = array(
'action' => 'download',
'slug' => $package->slug,
);
$result = self::addQueryArg($query, $this->serverUrl);
var_dump($query, $this->serverUrl, $result);
return $result;
}
This modified version will dump the values of the three main variables involved in download URL generation into the JSON output. You can then view the metadata URL in the browser and see if the values make sense. If it turns out that, for example, the $query array has the correct values for your plugin but addQueryArg() fails to properly append them to $this->serverUrl, the bug probably lies somewhere in addQueryArg() and that's the function we should investigate next.
Hi,
Okay, I've found something relevant. We're running PHP 5.4 on this server. Just to see if it was an issue with that version, I reverted to PHP 5.3. And the problem went away. (Well, I didn't test completely but the JSON data shows the proper URL in PHP 5.3.
So I'd assume that all your code is fine but there is some function or other element that is incompatible with PHP 5.4. I'm wondering what would be necessary to make it work in 5.4, as we'll need to keep current on PHP versions.
I hope this helps!
Thanks,
Mark
I also tested in PHP 5.5, and it seems to work there. So, to recap:
- 5.3 works
- 5.4 does not work
- 5.5 works
In each case the PHP configurations are identical in terms of modules (except for any that aren't supported in the particular version).
Again, hope this helps.
Interesting. Which minor version of PHP 5.4 are you using? I just tested it in PHP 5.4.3 and it output the correct download URL. This was when running the update server as a stand-alone script, not a WP plugin. The only issue I noticed was a bunch of unrelated E_STRICT warnings.
There doesn't seem to be any code that would be obviously incompatible with PHP 5.4, but it's possible that one of the functions or syntax features that it uses has a subtly different behaviour in your PHP version and that is what trips it up. I would still recommend adding some debugging code to the relevant method(s). Also, in case the problem is somehow related to closures, try commenting out these lines in UpdateServer.php:
//Remove null/false arguments.
$query = array_filter($query, function($value) {
return ($value !== null) && ($value !== false);
});
It is 5.4.19.
We can use PHP 5.5 as a workaround, however I'll follow your debugging suggestions and continue working on this in case we can help someone else using 5.4. I'll post any relevant results ASAP.
The problem seems to be solved by commenting out the lines you suggested:
//Remove null/false arguments.
$query = array_filter($query, function($value) {
return ($value !== null) && ($value !== false);
});
Hmm, are you completely sure it is PHP 5.4.19 and not something older? The only reason I can think of that would cause those lines to fail is if the PHP version used did not support closures. Closures were introduced in PHP 5.3.
By the way, I just tested it with PHP 5.4.19 (on Windows) and still could not reproduce the problem.