在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python/ python3使用requests訪(fǎng)問(wèn)asp頁(yè)面時(shí)出錯(cuò),返回500

python3使用requests訪(fǎng)問(wèn)asp頁(yè)面時(shí)出錯(cuò),返回500

學(xué)校的官微有個(gè)一鍵查成績(jī)的功能,我一直很想能做出來(lái)玩,現(xiàn)在在學(xué)習(xí)python,正好準(zhǔn)備拿來(lái)練手,但是訪(fǎng)問(wèn)的時(shí)候卻出現(xiàn)了500錯(cuò)誤。

以下是代碼:
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)上查詢(xún)了之后,發(fā)現(xiàn)可能是refer的問(wèn)題,但是更新refer的時(shí)候又出了問(wèn)題。

以下是輸出信息:

{'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

現(xiàn)在感覺(jué)有點(diǎn)暈,不知道應(yīng)該怎么做了。
順帶一提:我輸出登陸成功后的respons的源碼時(shí),發(fā)現(xiàn)也是不對(duì),說(shuō)明在登陸成功的頁(yè)面就出了問(wèn)題。

回答
編輯回答
尐潴豬

你應(yīng)該提供一個(gè)測(cè)試帳號(hào),不然誰(shuí)能幫你?

2017年4月21日 12:52