Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#27090 closed defect (bug) (invalid)

WordPress XML-RPC method returns error but still posts

Reported by: indigojo's profile IndigoJo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: XML-RPC Keywords:
Focuses: Cc:

Description

I am the developer of a desktop XML-RPC client for posting entries to blogs, and recently implemented the wp.newPost method (I had previously used the legacy metaWeblog.newPost method). I have found that when I post an entry with the status 'publish', WordPress often returns an error but still posts the entry. This means that it doesn't return an entry number for the post, so I cannot use the app to submit subsequent edits for the post. The legacy methods, when they returned an error, did not post the entry.

This is the entry I submitted this morning:

<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
 <methodName>wp.newPost</methodName>
 <params>
  <param>
   <value>
    <string>1</string>
   </value>
  </param>
  <param>
   <value>
    <string>mattsmith</string>
   </value>
  </param>
  <param>
   <value>
    <string>(password omitted)</string>
   </value>
  </param>
  <param>
   <value>
    <struct>
     <member>
      <name>post_type</name>
      <value>
       <string>post</string>
      </value>
     </member>
     <member>
      <name>post_status</name>
      <value>
       <string>publish</string>
      </value>
     </member>
     <member>
      <name>post_title</name>
      <value>
       <string>Bye-byePad</string>
      </value>
     </member>
     <member>
      <name>post_content</name>
      <value>
       <string>&lt;p>&lt;img src="http://www.blogistan.co.uk/blog/images/ipad-amazon-return.jpg" title="My iPad, packaged for return" alt="Picture of a white package sealed with packing tape with a label addressed to Amazon" style="float: right; margin-left: 5px; margin-bottom: 5px" />Well, I'm sending my iPad back to the vendor today. Amazon's policy is that an item is returnable for about a month, and I've had mine a week and a half (although I made this decision last Saturday, but have only just got round to printing out the return labels and packing it up).&lt;/p>

&lt;p>There are two reasons why I'm doing this. The most important is that I can't tolerate the keypad. It takes ages to type things that would take much less time on an Android tablet, simply because the better predictive text on Android saves you multiple keypresses on a screen that you can't touch-type on because it's too small. And there's just no alternative. Seriously, anyone migrating from Android is going to run up against this problem, and my advice is not to bother.&lt;/p>

&lt;p>The second is that it won't connect to certain wi-fi networks, and the reason I suspect is a bug which is preventing it sending passwords correctly on some forms (it did the same when logging into my own blog). You wouldn't think this was huge, but I've already got a tablet and that works fine -- £300 is too much to pay for a device that doesn't work properly, and doesn't allow you to find ways round its limitations.&lt;/p>

&lt;p>As for what I'm going to replace it with, I've been looking at the LG G-Pad, which costs about £50 less and has a similar size screen (although it's longer and the resolution is slightly less), but I might wait until April when it's rumoured that Google will be bringing out a Nexus 8. I'd ideally like to try it in a shop before buying it, but none of the major high-street computer shops stock it. What I'd really like is an Android tablet with the same dimensions and screen resolution, but there doesn't seem to be one and the shops seem to be selling Android tablets on the basis that they're cheap, not that they're good.&lt;/p>
</string>
      </value>
     </member>
     <member>
      <name>comment_status</name>
      <value>
       <string>open</string>
      </value>
     </member>
     <member>
      <name>ping_status</name>
      <value>
       <string>closed</string>
      </value>
     </member>
     <member>
      <name>terms</name>
      <value>
       <struct>
        <member>
         <name>category</name>
         <value>
          <array>
           <data>
            <value>
             <string>38</string>
            </value>
           </data>
          </array>
         </value>
        </member>
       </struct>
      </value>
     </member>
    </struct>
   </value>
  </param>
 </params>
</methodCall>


I'm using WordPress 3.8.1. My server logs do not reveal the source of this error and I don't have any error log plugin. The app uses the Qt network API and the error is an "Unknown Content Error", but I was unable to extract an HTTP error code from the content of the reply. None of the conditions for the three errors listed on the codex page for the wp API apply, and if they did, why would it post the entry?

Change History (8)

#1 @SergeyBiryukov
11 years ago

  • Summary changed from Wordpress XML-RPC method returns error but still posts to WordPress XML-RPC method returns error but still posts

#2 follow-up: @redsweater
11 years ago

This doesn't seem too pursuable without a reproduceable test case. The claims suggest that an error can be propagated from _insert_post in class-wp-xmlrpc-server.php at some point after the wp_insert_post call:

$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true );
if ( is_wp_error( $post_ID ) )
	return new IXR_Error( 500, $post_ID->get_error_message() );

if ( ! $post_ID )
	return new IXR_Error( 401, __( 'Sorry, your entry could not be posted. Something wrong happened.' ) );

return strval( $post_ID );

But more suspicious in this case is that the reporter doesn't see an actual error response from their networking library. I would be inclined to think this issue has something to do with their networking library or with their network connection. The post being published is consistent with there not actually being any error propagated from WordPress, but their networking library instead interpreting something about the response as an error condition.

#3 @redsweater
11 years ago

The report also suggests that the issue doesn't occur with the older metaweblog.newPost method. The window where a proper error could be propagated in that scenario is almost identical to the wp.newPost code path:

$post_ID = wp_insert_post( $postdata, true );
if ( is_wp_error( $post_ID ) )
	return new IXR_Error(500, $post_ID->get_error_message());

if ( !$post_ID )
	return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));

do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args );

return strval($post_ID);

Which suggests that if there is an issue it's in wp_insert_post itself, and that the difference in behavior between wp.newPost and metaweblog.newPost has to do with how the $postdata is prepared for wp_insert_post.

#4 in reply to: ↑ 2 @maxcutler
11 years ago

Replying to redsweater:

This doesn't seem too pursuable without a reproduceable test case.

redsweater is right, we need some more information to determine what's going on. IndigoJo, can you provide Fiddler/Charles traces of the network response (after stripping out any sensitive info)?

Or at least full details on the exception/error that you're getting from your network library? "Unknown Content Error" suggests that the issue is with the response body, perhaps an XML parsing issue or mismatched MIME-type or something along those lines.

#5 @IndigoJo
11 years ago

I've found the function to get the error string (which is in the Qt class inherited by QNetworkReply) so I've rewritten the app to output it, so next time I try submitting an entry I'll post it here.

#6 @IndigoJo
11 years ago

The error string read "Error downloading http://www.blogistan.co.uk/blog/xmlrpc.php - server replied: Internal Server Error".

It's happened every time I submit a post with Publish status using XML-RPC. Do the Wordpress apps for Android, iOS etc use the wp methods to submit posts? Last time I looked at the source code, they were still using the metaWeblog methods.

Last edited 11 years ago by IndigoJo (previous) (diff)

#7 @IndigoJo
11 years ago

Having tested the same app with the Social and Twitter Tools plugins disabled, the error's gone away.

#8 @wonderboymusic
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.