[tDiary-users-talk: 0485] ruby mechanizeで日記更新したい

Back to archive index

三輪晋( Miwa Susumu ) miwar****@gmail*****
2012年 1月 5日 (木) 23:54:35 JST


三輪と申します。

tdiary の問題ではなくて mechanize の使い方だと思うのですが、質問があります。

日記を ruby mechanize で更新しようとすると
サーバーから 500 が返答されてしまいます。

日記を更新するには append (追記)ボタンを submit すれば
いいのだと思ってるのですが間違ってるでしょうか。


[環境]
 tDiary 3.1.0
 NetBSD 5.1/i386
 ruby 1.8.6
 mechanize 1.0.0
 nokogiri 1.4.4


[詳細]
以下のようなコードを書きました。
user や pass には実際の文字列が入ります。
日記本文に「"!test\nhello tdiary!\n"」( wiki 書式です )を入力し
append ボタンを submit しようとしてます。


  #!/usr/pkg/bin/ruby -Ku

  require 'rubygems'
  require 'mechanize'
  require 'logger'

  def main
    @diary_uri = "http://www.area51.gr.jp/~rin/diary/update.rb"
    @diary_user = "USER"
    @diary_pass = "PASS"

    text = "!test\nhello tdiary!\n"

    agent = Mechanize.new
    agent.log = Logger.new($stdout)
    agent.log.level = Logger::INFO
    agent.auth(@diary_user, @diary_pass)
    agent.get(@diary_uri)
    agent.page.form_with(:action => "update.rb") { |form|
      form['body'] = text
      form.submit( form.button_with(:name => 'append'))
    }

  end

  main



[現象]
コードを実行すると以下のように出力されます。

  % ./tdwrite.rb
  I, [2012-01-05T23:35:45.022004 #10949]  INFO -- : Net::HTTP::Get:
/~rin/diary/update.rb
  I, [2012-01-05T23:35:45.099852 #10949]  INFO -- : status:
Net::HTTPUnauthorized 1.1 401 Authorization Required
  I, [2012-01-05T23:35:45.107026 #10949]  INFO -- : Net::HTTP::Get:
/~rin/diary/update.rb
  I, [2012-01-05T23:35:45.325946 #10949]  INFO -- : status:
Net::HTTPOK 1.1 200 OK
  I, [2012-01-05T23:35:45.383730 #10949]  INFO -- : form encoding: ISO-8859-1
  I, [2012-01-05T23:35:45.386748 #10949]  INFO -- : Net::HTTP::Post:
/~rin/diary/update.rb
  I, [2012-01-05T23:35:45.409135 #10949]  INFO -- : status:
Net::HTTPUnauthorized 1.1 401 Authorization Required
  I, [2012-01-05T23:35:45.418526 #10949]  INFO -- : Net::HTTP::Post:
/~rin/diary/update.rb
  I, [2012-01-05T23:35:45.518211 #10949]  INFO -- : status:
Net::HTTPInternalServerError 1.1 500 Internal Server Error
  /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:303:in
`fetch': 500 => Net::HTTPInternalServerError
(Mechanize::ResponseCodeError)
          from /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:655:in
`response_authenticate'
          from /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:300:in
`fetch'
          from /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:1036:in
`post_form'
          from /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:426:in
`submit'
          from /usr/pkg/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/form.rb:178:in
`submit'
          from ./tdwrite.rb:21:in `main'
          from (eval):23:in `form_with'
          from ./tdwrite.rb:19:in `main'
          from ./tdwrite.rb:26


ググると「サーバーのログを見ろ」というコメントがチラホラあるのですが
サーバー( httpd )のログにはそれらしいログがありません。
( tdiary とは関係ないログです )

  % tail /var/log/httpd/error_log
  [Thu Jan 05 23:25:08 2012] [error] (13)Permission denied: exec of
'/home/rin/public_html/diary-hns/index.cgi' failed
  [Thu Jan 05 23:25:08 2012] [error] [client 66.249.69.238] Premature
end of script headers: index.cgi
  [Thu Jan 05 23:29:14 2012] [error] [client 207.46.204.32] File does
not exist: /usr/pkg/share/httpd/htdocs/robots.txt
  [Thu Jan 05 23:32:09 2012] [error] [client 209.85.238.115] File does
not exist: /home/rin/public_html/hikifarm
  [Thu Jan 05 23:32:40 2012] [error] (13)Permission denied: exec of
'/home/rin/public_html/diary-hns/index.cgi' failed
  [Thu Jan 05 23:32:40 2012] [error] [client 66.249.69.238] Premature
end of script headers: index.cgi
  [Thu Jan 05 23:34:33 2012] [error] (13)Permission denied: exec of
'/home/rin/public_html/diary-hns/index.cgi' failed
  [Thu Jan 05 23:34:33 2012] [error] [client 66.249.69.238] Premature
end of script headers: index.cgi
  [Thu Jan 05 23:36:26 2012] [error] (13)Permission denied: exec of
'/home/rin/public_html/diary-hns/index.cgi' failed
  [Thu Jan 05 23:36:26 2012] [error] [client 66.249.69.238] Premature
end of script headers: index.cgi


どなたか mechanize で日記更新している方はいますでしょうか。

-- 
みわ




tDiary-users-talk メーリングリストの案内
Back to archive index