500 error in tdiary using mechanize
三輪晋( Miwa Susumu <miwarin <at> gmail.com>
2012-01-07 15:36:38 GMT
hi all
i use tdiary( The web diary system http://sourceforge.net/projects/tdiary/ ).
i am trying to update the diary with the mechanize.
i run the code (see below), mechanize returns
Net::HTTPInternalServerError (Mechanize::ResponseCodeError)
Googled Treats, that it's a server-side error.
(e.g. but perl... WWW::Mechanize::FAQ - search.cpan.org My Mech
program doesn't work, but it works in the browser.
http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod#My_Mech_program_doesn%27t_work,_but_it_works_in_the_browser.
)
However, there are no errors on the server side.
Do people know the cause?
In addition, web browser( Firefox ) can safely update my diary.
[Environment]
% ruby --version
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-netbsdelf]
% gem list
*** LOCAL GEMS ***
domain_name (0.5.1)
mechanize (2.1)
net-http-digest_auth (1.2)
net-http-persistent (2.3.3)
nokogiri (1.5.0)
ntlm-http (0.1.1)
tmail (1.2.7.1)
unf (0.0.4)
unf_ext (0.0.4)
webrobots (0.0.12)
* NetBSD 5.99.58
* tdiary 3.1.0
[code]
#!/usr/pkg/bin/ruby -Ku
require 'rubygems'
require 'mechanize'
require 'logger'
require 'pp'
def main
uri = "http://localhost/~rin/diary/update.rb"
user = "test"
pass = "test"
referer = "http://www.area51.gr.jp/~rin/diary/update.rb"
text = "!test\nhello tdiary!\n"
agent = Mechanize.new
agent.log = Logger.new($stdout)
# agent.log.level = Logger::INFO
agent.auth(user, pass) <= i use digest authentication
agent.get(uri, nil, referer)
agent.page.form_with(:action => "update.rb") { |form|
form['body'] = text
form.submit(form.button_with(:name => "append")) <=
seems to be an error here.
}
end
main
[mechanize log]
% ./tdwrite.rb
I, [2012-01-08T00:25:20.594807 #9165] INFO -- : Net::HTTP::Get:
/~rin/diary/update.rb
D, [2012-01-08T00:25:20.595147 #9165] DEBUG -- : request-header:
accept-language => en-us,en;q=0.5
D, [2012-01-08T00:25:20.595197 #9165] DEBUG -- : request-header: accept => */*
D, [2012-01-08T00:25:20.595264 #9165] DEBUG -- : request-header:
user-agent => Mechanize/2.1 Ruby/1.8.7p334
(http://github.com/tenderlove/mechanize/)
D, [2012-01-08T00:25:20.595308 #9165] DEBUG -- : request-header:
accept-encoding => gzip,deflate,identity
D, [2012-01-08T00:25:20.595352 #9165] DEBUG -- : request-header:
referer => http://www.area51.gr.jp/~rin/diary/update.rb
D, [2012-01-08T00:25:20.595395 #9165] DEBUG -- : request-header: host
=> localhost
D, [2012-01-08T00:25:20.595434 #9165] DEBUG -- : request-header:
accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
I, [2012-01-08T00:25:20.598261 #9165] INFO -- : status:
Net::HTTPUnauthorized 1.1 401 Authorization Required
D, [2012-01-08T00:25:20.598313 #9165] DEBUG -- : response-header:
content-type => text/html; charset=iso-8859-1
D, [2012-01-08T00:25:20.598359 #9165] DEBUG -- : response-header:
connection => Keep-Alive
D, [2012-01-08T00:25:20.598397 #9165] DEBUG -- : response-header:
www-authenticate => Digest realm="tDiary",
nonce="4NEBxvG1BAA=22e28cac4aac01662c270678d2355fbbfbe46395",
algorithm=MD5, qop="auth"
D, [2012-01-08T00:25:20.598433 #9165] DEBUG -- : response-header:
server => Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.9-dev DAV/2
D, [2012-01-08T00:25:20.598469 #9165] DEBUG -- : response-header: date
=> Sat, 07 Jan 2012 15:25:20 GMT
D, [2012-01-08T00:25:20.598504 #9165] DEBUG -- : response-header:
content-length => 290
D, [2012-01-08T00:25:20.598538 #9165] DEBUG -- : response-header:
content-encoding => gzip
D, [2012-01-08T00:25:20.598573 #9165] DEBUG -- : response-header:
keep-alive => timeout=5, max=100
D, [2012-01-08T00:25:20.598794 #9165] DEBUG -- : response-header: vary
=> Accept-Encoding
D, [2012-01-08T00:25:20.598965 #9165] DEBUG -- : Read 290 bytes (290 total)
D, [2012-01-08T00:25:20.599088 #9165] DEBUG -- : gzip body
I, [2012-01-08T00:25:20.605070 #9165] INFO -- : Net::HTTP::Get:
/~rin/diary/update.rb
D, [2012-01-08T00:25:20.605298 #9165] DEBUG -- : request-header:
accept-language => en-us,en;q=0.5
D, [2012-01-08T00:25:20.605371 #9165] DEBUG -- : request-header: accept => */*
D, [2012-01-08T00:25:20.605417 #9165] DEBUG -- : request-header:
user-agent => Mechanize/2.1 Ruby/1.8.7p334
(http://github.com/tenderlove/mechanize/)
D, [2012-01-08T00:25:20.605462 #9165] DEBUG -- : request-header:
accept-encoding => gzip,deflate,identity
D, [2012-01-08T00:25:20.605499 #9165] DEBUG -- : request-header:
authorization => Digest username="diary", realm="tDiary", qop=auth,
uri="/~rin/diary/update.rb",
nonce="4NEBxvG1BAA=22e28cac4aac01662c270678d2355fbbfbe46395",
nc=00000000, cnonce="a6a1370113ae4db8792628a3e87927e8",
response="c304545256e7e4d0a03c3e2d6ae4ec80"
D, [2012-01-08T00:25:20.605545 #9165] DEBUG -- : request-header:
referer => http://www.area51.gr.jp/~rin/diary/update.rb
D, [2012-01-08T00:25:20.605581 #9165] DEBUG -- : request-header: host
=> localhost
D, [2012-01-08T00:25:20.605616 #9165] DEBUG -- : request-header:
accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
I, [2012-01-08T00:25:20.755405 #9165] INFO -- : status: Net::HTTPOK 1.1 200 OK
D, [2012-01-08T00:25:20.755802 #9165] DEBUG -- : response-header:
content-type => text/html; charset=UTF-8
D, [2012-01-08T00:25:20.755878 #9165] DEBUG -- : response-header:
connection => Keep-Alive
D, [2012-01-08T00:25:20.755925 #9165] DEBUG -- : response-header:
authentication-info => rspauth="af4628a938bc6d2b04bf73ba60fb4a59",
cnonce="a6a1370113ae4db8792628a3e87927e8", nc=00000000, qop=auth
D, [2012-01-08T00:25:20.755962 #9165] DEBUG -- : response-header:
server => Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.9-dev DAV/2
D, [2012-01-08T00:25:20.755998 #9165] DEBUG -- : response-header: date
=> Sat, 07 Jan 2012 15:25:20 GMT
D, [2012-01-08T00:25:20.756032 #9165] DEBUG -- : response-header:
content-length => 7160
D, [2012-01-08T00:25:20.756067 #9165] DEBUG -- : response-header:
content-encoding => gzip
D, [2012-01-08T00:25:20.756102 #9165] DEBUG -- : response-header:
keep-alive => timeout=5, max=99
D, [2012-01-08T00:25:20.756137 #9165] DEBUG -- : response-header: vary
=> User-Agent,Accept-Encoding
D, [2012-01-08T00:25:20.756250 #9165] DEBUG -- : Read 7160 bytes (7160 total)
D, [2012-01-08T00:25:20.756403 #9165] DEBUG -- : gzip body
I, [2012-01-08T00:25:20.772181 #9165] INFO -- : form encoding: ISO-8859-1
D, [2012-01-08T00:25:20.774358 #9165] DEBUG -- : query:
"old=20120108&year=2012&month=1&day=8&title=&body=%21test%0Ahello+tdiary%21%0A&plugin_ping_send=true&api=0&plugin_tags_filter=on&plugin_tb_url=&plugin_tb_section=p01&plugin_tb_excerpt=&append=+%E8%BF%BD%E8%A8%98+"
I, [2012-01-08T00:25:20.775397 #9165] INFO -- : Net::HTTP::Post:
/~rin/diary/update.rb
D, [2012-01-08T00:25:20.775641 #9165] DEBUG -- : request-header:
accept-language => en-us,en;q=0.5
D, [2012-01-08T00:25:20.775879 #9165] DEBUG -- : request-header: accept => */*
D, [2012-01-08T00:25:20.776086 #9165] DEBUG -- : request-header:
content-type => application/x-www-form-urlencoded
D, [2012-01-08T00:25:20.776280 #9165] DEBUG -- : request-header:
user-agent => Mechanize/2.1 Ruby/1.8.7p334
(http://github.com/tenderlove/mechanize/)
D, [2012-01-08T00:25:20.776507 #9165] DEBUG -- : request-header:
accept-encoding => gzip,deflate,identity
D, [2012-01-08T00:25:20.776697 #9165] DEBUG -- : request-header:
content-length => 211
D, [2012-01-08T00:25:20.776922 #9165] DEBUG -- : request-header:
referer => http://diary:diary <at> localhost/~rin/diary/update.rb
D, [2012-01-08T00:25:20.777128 #9165] DEBUG -- : request-header: host
=> localhost
D, [2012-01-08T00:25:20.777381 #9165] DEBUG -- : request-header:
accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
I, [2012-01-08T00:25:20.778814 #9165] INFO -- : status:
Net::HTTPUnauthorized 1.1 401 Authorization Required
D, [2012-01-08T00:25:20.779127 #9165] DEBUG -- : response-header:
content-type => text/html; charset=iso-8859-1
D, [2012-01-08T00:25:20.779357 #9165] DEBUG -- : response-header:
connection => Keep-Alive
D, [2012-01-08T00:25:20.779569 #9165] DEBUG -- : response-header:
www-authenticate => Digest realm="tDiary",
nonce="6ZYExvG1BAA=98d27d517f0275958fb5065ff69c8088ea850008",
algorithm=MD5, qop="auth"
D, [2012-01-08T00:25:20.779818 #9165] DEBUG -- : response-header:
server => Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.9-dev DAV/2
D, [2012-01-08T00:25:20.780037 #9165] DEBUG -- : response-header: date
=> Sat, 07 Jan 2012 15:25:20 GMT
D, [2012-01-08T00:25:20.780231 #9165] DEBUG -- : response-header:
content-length => 290
D, [2012-01-08T00:25:20.780439 #9165] DEBUG -- : response-header:
content-encoding => gzip
D, [2012-01-08T00:25:20.780628 #9165] DEBUG -- : response-header:
keep-alive => timeout=5, max=98
D, [2012-01-08T00:25:20.780847 #9165] DEBUG -- : response-header: vary
=> Accept-Encoding
D, [2012-01-08T00:25:20.781100 #9165] DEBUG -- : Read 290 bytes (290 total)
D, [2012-01-08T00:25:20.781460 #9165] DEBUG -- : gzip body
I, [2012-01-08T00:25:20.787175 #9165] INFO -- : Net::HTTP::Post:
/~rin/diary/update.rb
D, [2012-01-08T00:25:20.787408 #9165] DEBUG -- : request-header:
accept-language => en-us,en;q=0.5
D, [2012-01-08T00:25:20.787652 #9165] DEBUG -- : request-header: accept => */*
D, [2012-01-08T00:25:20.787889 #9165] DEBUG -- : request-header:
content-type => application/x-www-form-urlencoded
D, [2012-01-08T00:25:20.788136 #9165] DEBUG -- : request-header:
user-agent => Mechanize/2.1 Ruby/1.8.7p334
(http://github.com/tenderlove/mechanize/)
D, [2012-01-08T00:25:20.788393 #9165] DEBUG -- : request-header:
accept-encoding => gzip,deflate,identity
D, [2012-01-08T00:25:20.788710 #9165] DEBUG -- : request-header:
authorization => Digest username="diary", realm="tDiary", qop=auth,
uri="/~rin/diary/update.rb",
nonce="6ZYExvG1BAA=98d27d517f0275958fb5065ff69c8088ea850008",
nc=00000001, cnonce="a6a1370113ae4db8792628a3e87927e8",
response="a903c6e42ed5896cd1da05516fc5b93d"
D, [2012-01-08T00:25:20.789087 #9165] DEBUG -- : request-header:
content-length => 211
D, [2012-01-08T00:25:20.789302 #9165] DEBUG -- : request-header:
referer => http://diary:diary <at> localhost/~rin/diary/update.rb
D, [2012-01-08T00:25:20.789520 #9165] DEBUG -- : request-header: host
=> localhost
D, [2012-01-08T00:25:20.789711 #9165] DEBUG -- : request-header:
accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
I, [2012-01-08T00:25:20.842091 #9165] INFO -- : status:
Net::HTTPInternalServerError 1.1 500 Internal Server Error
D, [2012-01-08T00:25:20.842477 #9165] DEBUG -- : response-header:
content-type => text/html
D, [2012-01-08T00:25:20.842718 #9165] DEBUG -- : response-header:
connection => close
D, [2012-01-08T00:25:20.842961 #9165] DEBUG -- : response-header:
authentication-info => rspauth="f92b2000ce402faad6c351d19abdc07c",
cnonce="a6a1370113ae4db8792628a3e87927e8", nc=00000001, qop=auth
D, [2012-01-08T00:25:20.843216 #9165] DEBUG -- : response-header:
server => Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.9-dev DAV/2
D, [2012-01-08T00:25:20.843419 #9165] DEBUG -- : response-header: date
=> Sat, 07 Jan 2012 15:25:20 GMT
D, [2012-01-08T00:25:20.843644 #9165] DEBUG -- : response-header:
content-length => 416
D, [2012-01-08T00:25:20.843865 #9165] DEBUG -- : response-header:
content-encoding => gzip
D, [2012-01-08T00:25:20.844076 #9165] DEBUG -- : response-header: vary
=> Accept-Encoding
D, [2012-01-08T00:25:20.844377 #9165] DEBUG -- : Read 416 bytes (416 total)
D, [2012-01-08T00:25:20.844808 #9165] DEBUG -- : gzip body
/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:24:in `main'
from (eval):23:in `form_with'
from ./tdwrite.rb:22:in `main'
from ./tdwrite.rb:29
[apache web server access_log]
127.0.0.1 - - [08/Jan/2012:00:25:20 +0900] "GET /~rin/diary/update.rb
HTTP/1.1" 401 290
127.0.0.1 - diary [08/Jan/2012:00:25:20 +0900] "GET
/~rin/diary/update.rb HTTP/1.1" 200 7160
127.0.0.1 - - [08/Jan/2012:00:25:20 +0900] "POST /~rin/diary/update.rb
HTTP/1.1" 401 290
127.0.0.1 - diary [08/Jan/2012:00:25:20 +0900] "POST
/~rin/diary/update.rb HTTP/1.1" 500 416
[apache web server error_log]
(In particular there are no errors)
--
--
miwa