楽しいため、私は学校の学生ポータルにログオンするためにPythonリクエストを使用しようとしています。これはこれまで私が思いついたことです。 302(成功したログイン)ではなく、200ステータスコード(ログインに失敗したときに取得するコード)を取得しているため、ヘッダーを明示的に表示しようとしています。ネットワーク要求を調べるためにChromeを使用し要求のあるサイトにログインできません
import sys
import os
import requests
def login(username, password):
url = '(link)/home.html#sign-in-content'
values = {
'translator_username' : '',
'translator_password' : '',
'translator_ldappassword' : '',
'returnUrl' : '',
'serviceName' : 'PS Parent Portal',
'serviceTicket' : '',
'pcasServerUrl' : '\/',
'credentialType' : 'User Id and Password Credential',
'account' : username,
'pw' : password,
'translatorpw' : password
}
headers = {
'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding' : 'gzip, deflate, br',
'accept-language' : 'en-US,en;q=0.9',
'cache-control' : 'max-age=0',
'connection' : 'keep-alive',
'content-type' : 'application/x-www-form-urlencoded',
'host' : '(link)',
'origin' : '(link)',
'referer' : '(link)guardian/home.html',
'upgrade-insecure-requests' : '1'
}
with requests.Session() as s:
p = s.post(url, data=values)
if p.status_code == 302:
print(p.text)
print('Authentication error', p.status_code)
r = s.get('(link)guardian/home.html')
print(r.text)
def main():
login('myname', 'mypass')
if __name__ == '__main__':
main()
、これらのヘッダのすべてが長いクッキーの数、コンテンツの長さ、およびユーザエージェントに加えて、「リクエストヘッダ」の下にあります。次のように
形式は以下のとおりです。
pstoken:(token)
contextData:(text)
translator_username:
translator_password:
translator_ldappassword:
returnUrl:(url)guardian/home.html
serviceName:PS Parent Portal
serviceTicket:
pcasServerUrl:\/
credentialType:User Id and Password Credential
account:f
pw:(id)
translatorpw:
私は、ヘッダー/フォーム名と何かが足りないのですか?クッキーには問題がありますか?
私はp.requests.headersを見れば、これは送信されているものです。
{'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36', 'accept-encoding': 'gzip, deflate, br', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'connection': 'keep-alive', 'accept-language': 'en-US,en;q=0.9', 'cache-control': 'max-age=0', 'content-type': 'application/x-www-form-urlencoded', 'host': '(url)', 'origin': '(url)', 'referer': '(url)guardian/home.html', 'upgrade-insecure-requests': '1', 'Content-Length': '263'}
p.textは私にPowerAPI、リクエスト、Mechanizeのでテストログインページ
のHTMLを与え、ロボブラウザー。すべて失敗します。
を私達にあなたの要求とその応答の例を与えます。 – Sraw
@Sraw私が修正した記事の一番下を参照してください。 –
これはPowerSchoolのログインフォームに役立つ場合 –