首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python中的帐户身份验证post方法请求

python中的帐户身份验证post方法请求
EN

Stack Overflow用户
提问于 2020-12-26 15:09:14
回答 1查看 67关注 0票数 0

在下面的代码中,我尝试对microsoft online帐户执行POST方法,并且我从一个需要发布电子邮件的页面开始。这是我到现在为止的尝试

代码语言:javascript
复制
import requests
from bs4 import BeautifulSoup

url = 'https://moe-register.emis.gov.eg/account/login?ReturnUrl=%2Fhome%2FRegistrationForm'
headers ={
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,ar;q=0.8',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie':'__RequestVerificationToken=vdS3aPPg5qQ2bH9ADTppeKIVJfclPsMI6dqB6_Ru11-2XJPpLfs7jBlejK3n0PZuYl-CwuM2hmeCsXzjZ4bVfj2HGLs2KOfBUphZHwO9cOQ1; .AspNet.MOEEXAMREGFORM=ekeG7UWLA6OSbT8ZoOBYpC_qYMrBQMi3YOwrPGsZZ_3XCuCsU1BP4uc5QGGE2gMnFgmiDIbkIk_8h9WtTi-P89V7ME6t_mBls6T3uR2jlllCh0Ob-a-a56NaVNIArqBLovUnLGMWioPYazJ9DVHKZY7nR_SvKVKg2kPkn6KffkpzzHOUQAatzQ2FcStZBYNEGcfHF6F9ZkP3VdKKJJM-3hWC8y62kJ-YWD0sKAgAulbKlqcgL1ml6kFoctt2u66eIWNm3ENnMbryh8565aIk3N3UrSd5lBoO-3Qh8jdqPCCq38w3cURRzCd1Z1rhqYb3V2qYs1ULRT1_SyRXFQLrJs5Y9fsMNkuZVeDp_CKfyzM',
'Host': 'moe-register.emis.gov.eg',
'Origin': 'https://moe-register.emis.gov.eg',
'Referer': 'https://moe-register.emis.gov.eg/account/login?ReturnUrl=%2Fhome%2FRegistrationForm',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'}


with requests.session() as s:
   # r = s.post(url)
    #soup = BeautifulSoup(r.content, 'lxml')

    data = {'EmailAddress': '476731809@matrouh1.moe.edu.eg'}
    r_post = s.post(url, data=data, headers=headers, verify=False)
    soup = BeautifulSoup(r_post.content, 'lxml')
    print(soup)

我得到的是相同的页面,要求再次发布电子邮件。我希望得到需要登录密码的页面..

This是起始页,这是需要发布476731809@matrouh1.moe.edu.eg的电子邮件的示例

**我曾尝试使用这样的代码,但我再次获得页面登录(尽管凭据是正确的)您可以尝试此代码吗

代码语言:javascript
复制
import requests
from bs4 import BeautifulSoup

url = 'https://login.microsoftonline.com/common/login'
s = requests.Session()
res = s.get('https://login.microsoftonline.com')
cookies = dict(res.cookies)
res = s.post(url, 
    auth=('476731809@matrouh1.moe.edu.eg', 'Std#050202'),
    verify=False, 
    cookies=cookies)
soup = BeautifulSoup(res.text, 'html.parser')
print(soup)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-26 15:19:16

我查看了这个页面,下面的内容似乎起作用了:

代码语言:javascript
复制
import requests

headers = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
    'Upgrade-Insecure-Requests': '1',
    'Origin': 'https://moe-register.emis.gov.eg',
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-User': '?1',
    'Sec-Fetch-Dest': 'document',
    'Referer': 'https://moe-register.emis.gov.eg/account/login',
    'Accept-Language': 'en-US,en;q=0.9,gl;q=0.8,fil;q=0.7,hi;q=0.6',
}

data = {
    'EmailAddress': '476731809@matrouh1.moe.edu.eg'
}

response = requests.post('https://moe-register.emis.gov.eg/account/authenticate', headers=headers, data=data, verify=False)

您的POST端点似乎是错误的,因为您需要从/login重定向到/authenticate才能继续处理请求(我在mac上,所以我的用户代理可能与您的/required不同,您可以通过headers变量更改它)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65454274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档