urllib2.HTTPError:HTTP错误405:方法不允许,为什么会发生?

时间:2012-07-15 23:46:51

标签: javascript python python-2.7 urllib http-status-code-405

我搜索了我的问题,但我找不到任何明确的解决方案。

这是我的代码

import urllib, urllib2, cookielib
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username':'USER','password':'PASS','SignOnTo':'1012'})
x0=opener.open('https://example.com/English/common/HTML/Login.html', login_data)
print x0.geturl()

然后我得到了这个urllib2.HTTPError: HTTP Error 405: Method Not Allowed

所以这是登录的FORM以确保我的代码是正确的

<form autocomplete="OFF" name="LoginForm" method="post">
<input readonly="" maxlength="15" size="18" onfocus="blur()" class="CurPosClass" name="username">
<input type="password" readonly="" maxlength="10" size="18" onfocus="blur()" class="ResetPosClass" name="password">
<div onclick="javascript:fn_login()" class="loginLayerH">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>

另外我使用tamper data {plugin in firefox}检查输出参数 并且只有三个我已将它们添加到字典{login_data}


检查后

这是函数fn_login

function fn_login() 
   {    
         var checklen = document.LoginForm.password.value.length;
         document.cookie = "CheckLenP ="+checklen+";path = /"+";domain =.example.com;SECURE";
         if(isAutoReg() && (switchIndex(signin,"-")!=-1))
        {   
                var sAutoregUrl=solRealm + "/apps/consumer/autoreg/welcome.jsp?Language=E";                  
                document.cookie = "TargetUrl ="+sAutoregUrl+";path = /"+";domain =.example.com";     
                document.LoginForm.action=solRealm + "/common/ebank/autoregp6.jsp";           
                document.LoginForm.submit();        
        }
         else
        {           
                var sUserId = document.LoginForm.username.value;
                var sPwd    = document.LoginForm.password.value;
                var signin = document.LoginForm.SignOnTo.value;                 

                 if(switchIndex(signin,"-")==-1)
                {
                        loginurl = tdlRealm + "/secure/examplelogin.dll";         
                        document.LoginForm.action = loginurl;   
                        document.cookie = "TargetUrl =" + tdlRealm + "/apps/consumer/ITS/welcome.jsp?Language=E" +";path = /"+";domain =.example.com";                                                                                          
                }
                 else
                {
                        loginurl = solRealm + "/secure/" + "examplelogin.dll";         
                        document.LoginForm.action = loginurl;   
                        document.cookie = "TargetUrl =" + solRealm + "/apps/consumer/ops/welcome.jsp?Language=E" +";path = /"+";domain =.example.com";                                  
                }

                 if(sUserId.length < 1) 
                {                       
                        alert('User Name field should not be empty, Click Tab to move between User Name and Password boxes');                   
                        return false;
                }
                 if(sPwd.length < 1) 
                {
                        alert('Password field should not be empty, Click Tab to move between User Name and Password boxes');
                        return false;
                } 
                var szSelectedScreen = signin;
                var dt = new Date(2012,1,1);
                document.cookie = "SOLPreferedPage="+szSelectedScreen+";expires="+dt.toGMTString()+";path=/"+";domain=.example.com";                                              
                document.LoginForm.submit();                    
        }
   } 

0 个答案:

没有答案