![](/img/trans.png)
[英]Getting error “getaddrinfo: No such host is known. (Socke tError)” with mechanize gem
[英]Can't use RubyPress gem gives getaddrinfo: No such host is known. (SocketError)
我正在嘗試使用一個名為RubyPress的寶石,該寶石可以使用來自ruby的Wordpress的xml-rpc api。 但這總是給我這個錯誤:
getaddrinfo: No such host is known. (SocketError)
這是我的代碼:
require 'rubypress'
wp = Rubypress::Client.new(:host => "localhost/wordpress",
:username => "admin",
:password => "admin")
p wp.getOptions
我可以使用另一個名為wp_rpc的 gem很好地連接,但是rubypress似乎不起作用。 Rubypress似乎得到了維護,因此我想使用它,它似乎還具有更多功能。
另外,即使我嘗試連接到真實站點,它也會顯示403錯誤,這非常奇怪。
我正在Windows 7上使用XAMPP運行服務器。如何使它工作?
更新:這是我用於發布的代碼,現在似乎沒有發布。 不知道我在哪里錯了。
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']
}
}
)
注意:這來自rubypress github頁面。 這些類別和標簽沒有出現在博客上,這是原因嗎?
host
必須是一個主機名(例如,在這種情況下為"localhost"
,例如"google.com"
):
require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
username: "admin",
password: "admin",
path: "/wordpress/xmlrpc.php")
可能您可能需要調整path
參數,以精確指向要在其中找到WP的RPC端點的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.