python asp.net requests_python3使用requests访问asp页面时出错,返回500
學(xué)校的官微有個一鍵查成績的功能,我一直很想能做出來玩,現(xiàn)在在學(xué)習(xí)python,正好準(zhǔn)備拿來練手,但是訪問的時候卻出現(xiàn)了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)
我在網(wǎng)上查詢了之后,發(fā)現(xiàn)可能是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'}
{'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'}
Process finished with exit code 0
現(xiàn)在感覺有點暈,不知道應(yīng)該怎么做了。
順帶一提:我輸出登陸成功后的respons的源碼時,發(fā)現(xiàn)也是不對,說明在登陸成功的頁面就出了問題。
總結(jié)
以上是生活随笔為你收集整理的python asp.net requests_python3使用requests访问asp页面时出错,返回500的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: docker容器化python开发环境_
- 下一篇: python条形图一直长_条形图的坐标轴