gpt4 book ai didi

ruby-on-rails - 验证时 Mechanize 405 错误

转载 作者:行者123 更新时间:2023-12-04 16:22:41 25 4
gpt4 key购买 nike

我正在尝试使用 Mechanize gem 对网站进行身份验证,但收到以下错误:

405 => Net::HTTPMethodNotAllowed for https://www.mygreatlakes.org/educate/login/snapAuthentication -- unhandled response

表格使用 POST作为方法,所以我不确定为什么会发生这个错误。使用 Hurl It ,我能够看到这个 URL 接受 GET 请求。访问此 URL 会返回 401 错误,说明
Error 401: Authentication Failed: Authentication method not supported: GET

也许这也值得注意:表单外有一个用户名输入和另一个输入,我想知道它们在表单外的位置是否意味着使用 JavaScript 将这些附加到请求中?

这是我用来登录的代码:
  def scraper
agent = Mechanize.new { |a| a.log = Logger.new("log/mechanize.log") }
agent.request_headers = {'User-agent' => 'Mozilla/5.0 (Windows NT 5.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11'}

login_page = agent.get('https://www.mygreatlakes.org/educate/login.html')
login_form = login_page.form_with(id: 'snapLogin')
username_field = login_form.field_with(name: "userName")
username_field.value = "username"
login_page = login_form.submit

pin_form = login_page.form_with(id: 'securityPinModel')
pin_field = pin_form.field_with(name: "pinNumber")
pin_field.value = "pin"
pin_page = pin_form.submit

password_form = pin_page.form_with(id: "frm")
password_field = password_form.field_with(name: "password")
password_field.value = "password"
password_page = password_form.submit

@output = password_page.body
end

这是抛出错误的密码页面上表单中的 HTML:
<form id="frm" class="slow-load log-in" autocomplete="OFF" action="snapAuthentication" method="post">
<div id="errors" class="message alert hide-this authErrors" role="alert" style="display: none;">
<strong>Please Correct These Errors</strong><br>
<ul id="errorList" style="outline: none;" tabindex="-1">

</ul>
</div>


<div>
<p>Here's the identity image and catchphrase you selected:</p>
<p class="display-img">
<img style="height: 65px; width: 65px;" alt="Pirate Flag" src="image.img?id=7">
<br>
<strong class="blue">catchphrase</strong>
</p>
</div>
<div>
<label for="password">Password</label>
<input id="password" name="password" class="short input-field" type="password" value="" autocomplete="off">
</div>
<button type="submit" class="orange" id="authenticate">Continue</button>
<p class="help"><a class="nowrap" href="/educate/login/trouble.html">I forgot my password</a></p>
</form>
<input id="userName" name="userName" type="hidden" value="username">
<input type="hidden" name="_csrf" value="value">

这是我的日志文件:
I, [2015-11-08T21:26:22.626822 #48752]  INFO -- : form encoding: utf-8
D, [2015-11-08T21:26:22.626999 #48752] DEBUG -- : query: "password=password"
I, [2015-11-08T21:26:22.629630 #48752] INFO -- : Net::HTTP::Post: /educate/login/snapAuthentication
D, [2015-11-08T21:26:22.629804 #48752] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2015-11-08T21:26:22.629886 #48752] DEBUG -- : request-header: accept => */*
D, [2015-11-08T21:26:22.629956 #48752] DEBUG -- : request-header: user-agent => Mozilla/5.0 (Windows NT 5.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
D, [2015-11-08T21:26:22.630022 #48752] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2015-11-08T21:26:22.630087 #48752] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2015-11-08T21:26:22.630168 #48752] DEBUG -- : request-header: cookie => GLDCID=.mad; JSESSIONID_007_infoserv=0001LgdwpswRf5r66r4pAgOtaOM:153b6ufq4; TLTSID=0.5241251b52c6a
D, [2015-11-08T21:26:22.630235 #48752] DEBUG -- : request-header: host => www.mygreatlakes.org
D, [2015-11-08T21:26:22.630310 #48752] DEBUG -- : request-header: referer => https://www.mygreatlakes.org/educate/login/imageAndPassword.html
D, [2015-11-08T21:26:22.630377 #48752] DEBUG -- : request-header: content-type => application/x-www-form-urlencoded
D, [2015-11-08T21:26:22.630441 #48752] DEBUG -- : request-header: content-length => 17
I, [2015-11-08T21:26:22.680558 #48752] INFO -- : status: Net::HTTPMethodNotAllowed 1.1 405 Method Not Allowed
D, [2015-11-08T21:26:22.680816 #48752] DEBUG -- : response-header: date => Mon, 09 Nov 2015 02:26:22 GMT
D, [2015-11-08T21:26:22.680936 #48752] DEBUG -- : response-header: server => Apache
D, [2015-11-08T21:26:22.681050 #48752] DEBUG -- : response-header: strict-transport-security => max-age=31536000 ; includeSubDomains
D, [2015-11-08T21:26:22.681164 #48752] DEBUG -- : response-header: x-xss-protection => 1; mode=block
D, [2015-11-08T21:26:22.681274 #48752] DEBUG -- : response-header: x-frame-options => DENY
D, [2015-11-08T21:26:22.681384 #48752] DEBUG -- : response-header: x-content-type-options => nosniff
D, [2015-11-08T21:26:22.681493 #48752] DEBUG -- : response-header: allow => GET,HEAD
D, [2015-11-08T21:26:22.681601 #48752] DEBUG -- : response-header: content-length => 0
D, [2015-11-08T21:26:22.681710 #48752] DEBUG -- : response-header: content-type => text/plain; charset=ISO-8859-1
D, [2015-11-08T21:26:22.681818 #48752] DEBUG -- : response-header: content-language => en-US
D, [2015-11-08T21:26:22.681926 #48752] DEBUG -- : response-header: keep-alive => timeout=4, max=95
D, [2015-11-08T21:26:22.682098 #48752] DEBUG -- : response-header: connection => Keep-Alive
D, [2015-11-08T21:26:22.682332 #48752] DEBUG -- : Read 0 bytes (0 total)

最佳答案

该错误意味着该站点正在阻止您尝试连接到它的方法。

基本上,该站点的管理员正在阻止您尝试使用的特定方法或该站点处于“只读”状态,但是您可以删除此阻止,这是一个教您如何操作的链接:

http://www.checkupdown.com/status/E405.html

至于 401 错误,它可能表示旧的缓存数据、丢失的 cookie 或安全冲突。 401 错误也可能表示服务器错误。

关于ruby-on-rails - 验证时 Mechanize 405 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33601650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com