学校的官微有个一键查成绩的功能,我一直很想能做出来玩,现在在学习python,正好准备拿来练手,但是访问的时候却出现了500错误。
以下是代码:
python
import requests
import time
import hashlib
from user import user
url1 = 'http://202.115.133.173:805/Common/Handler/UserLogin.ashx'
url2 = 'http://202.115.133.173:805/Default.aspx'
url3 = 'http://202.115.133.173:805/MyMessage/MyMsgForm.aspx'
username = user.name
password = user.pwd
sign = int(time.time()*1000)
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, compress',
'Accept-Language': 'en-us;q=0.5,en;q=0.3',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Host':'202.115.133.173:805',
'Referer':'',
'Upgrade-Insecure-Requests':'1',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'
}
def treatpwd(user, sign, pwd):
pwdmd5 = hashlib.md5()
pwdmd5.update(pwd.encode("utf-8"))
loginpwd = pwdmd5.hexdigest()
return loginpwd
datas = {
'Action':'Login',
'userName':username,
'pwd':treatpwd(username, sign, password),
'sign':sign,
}
if name == "__main__":
req = requests.Session()
headers['Referer'] = url1
print(headers)
req.headers.update(headers)
resp1 = req.post(url1,data=datas)
print(resp1)
headers['Referer'] = url1
print(headers)
req.headers.update(headers)
print(req.headers)
resp2 = req.get(url2)
print(resp2.headers)
headers['Referer'] = url2
req.headers.update(headers)
resp3 = req.get(url3)
print(resp3.headers)
print(resp3)
我在网上查询了之后,发现可能是refer的问题,但是更新refer的时候又出了问题。
以下是输出信息:
{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Accept-Encoding': 'gzip, deflate, compress', 'Accept-Language': 'en-us;q=0.5,en;q=0.3', 'Cache-Control': 'max-age=0', 'Connection': 'keep-alive', 'Host': '202.115.133.173:805', 'Referer': 'http://202.115.133.173:805/Common/Handler/UserLogin.ashx', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
<Response [200]>
{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Accept-Encoding': 'gzip, deflate, compress', 'Accept-Language': 'en-us;q=0.5,en;q=0.3', 'Cache-Control': 'max-age=0', 'Connection': 'keep-alive', 'Host': '202.115.133.173:805', 'Referer': 'http://202.115.133.173:805/Common/Handler/UserLogin.ashx', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
{'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0', 'Accept-Encoding': 'gzip, deflate, compress', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Connection': 'keep-alive', 'Accept-Language': 'en-us;q=0.5,en;q=0.3', 'Cache-Control': 'max-age=0', 'Host': '202.115.133.173:805', 'Referer': 'http://202.115.133.173:805/Common/Handler/UserLogin.ashx', 'Upgrade-Insecure-Requests': '1'}
{'Content-Type': 'text/html', 'Content-Encoding': 'gzip', 'Last-Modified': 'Thu, 23 Nov 2017 03:09:08 GMT', 'Accept-Ranges': 'bytes', 'ETag': '"0a24a6d864d31:0"', 'Vary': 'Accept-Encoding', 'Server': 'Microsoft-IIS/7.5', 'X-Powered-By': 'ASP.NET', 'Date': 'Sat, 07 Apr 2018 13:19:10 GMT', 'Content-Length': '1329'}
{'Cache-Control': 'private', 'Content-Type': 'text/html; charset=utf-8', 'Server': 'Microsoft-IIS/7.5', 'X-AspNet-Version': '4.0.30319', 'X-Powered-By': 'ASP.NET', 'Date': 'Sat, 07 Apr 2018 13:19:11 GMT', 'Content-Length': '4179'}
<Response [500]>
Process finished with exit code 0
现在感觉有点晕,不知道应该怎么做了。
顺带一提:我输出登陆成功后的respons的源码时,发现也是不对,说明在登陆成功的页面就出了问题。
你应该提供一个测试帐号,不然谁能帮你?