简体   繁体   中英

Can't use RubyPress gem gives getaddrinfo: No such host is known. (SocketError)

I am trying to use a gem called RubyPress which allows to use Wordpress' xml-rpc api from ruby. But it always gives me this error:

getaddrinfo: No such host is known.  (SocketError)

Here's my code:

require 'rubypress'
wp = Rubypress::Client.new(:host => "localhost/wordpress", 
                           :username => "admin", 
                           :password => "admin")
p wp.getOptions

I am able to connect fine using another gem called wp_rpc but rubypress doesn't seem to work. Rubypress seems to be maintained so i want to use it, it also seems to have more features.

Also, even when i try connecting to a real site, it gives a 403 error which is very strange.

I am running the server using XAMPP on Windows 7. How can I get it to work?

UPDATE: Here's the code i used for posting, now it doesn't seem to post. Not sure where i went wrong.

wp.newPost( :blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id
            :content => {
                         :post_status  => "publish",
                         :post_date    => Time.now,
                         :post_content => "This is the body",
                         :post_title   => "RubyPress is the best!",
                         :post_name    => "/rubypress-is-the-best",
                         :post_author  => 1, # 1 if there is only the admin user, otherwise the user's id
                         :terms_names  => {
                            :category   => ['Category One','Category Two','Category Three'],
                            :post_tag => ['Tag One','Tag Two', 'Tag Three']
                                          }
                         }
            ) 

Note: This is from the rubypress github page. Those categories and tags are not present on the blog, is that the reason?

host must be a host name (eg "localhost" in this particular case, or, say, "google.com" ):

require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
                           username: "admin",
                           password: "admin",
                           path: "/wordpress/xmlrpc.php")

Probably, you might need to tune the path parameter up to point exactly to where WP's RPC endpoint is to be found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM