为什么我得到一个正确的python请求(400个错误请求)?

2024-03-29 14:46:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python请求登录数据和验证。登录响应我200好,但验证是400坏请求!!你知道吗

# -*- coding: utf-8 -*-

import requests
import json

post_data = {
    'response_type': 'code',
    'scope': 'openid+offline_access',
    'redirect_uri': 'https:%3A%2F%2Fapi.asiamiles.com%2Fprofile%2Fapi%2Fv2%2FcreateSessionAndRedirect',
    'login_url': 'https%3A%2F%2Fwww.asiamiles.com%2Fen%2Flogin.html',
    'target_url': 'https%3A%2F%2Fwww.asiamiles.com%2Fen%2Faccount%2Faccount-overview.html',
    'state': '',
    'username': '1707990235',
    'password': '*123qweQWE',
}

url = 'https://api.cathaypacific.com/mlc2/authorize'
opener = requests.sessions.session()
temp = opener.post(url=url,data=post_data)
print(temp.status_code,temp.reason)

jsondata = {"channel": "Voice", "language": "en", "voiceCallLanguage": "", "username": "ltxbjhnomx", "Number": "972592781582"}
josned = json.dumps(jsondata)
urrl = 'https://api.asiamiles.com/profile/api/v1/1707990235/mobile-verify/send-mobile-code'
smsheader = {
    'Host': 'api.asiamiles.com',
    'Connection': 'keep-alive',
    'Accept': 'application/json, text/plain, */*',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
    'Sec-Fetch-Mode': 'cors',
    'Content-Type': 'application/json;charset=UTF-8',
    'Origin': 'https://www.asiamiles.com',
    'Sec-Fetch-Site': 'same-site',
    'Referer': 'https://www.asiamiles.com/en/mobile-verification.html?targetURL=https://www.asiamiles.com/en/account/account-overview.html',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'ar-EG,ar;q=0.9,en-US;q=0.8,en;q=0.7',
}

verify = opener.post(url=urrl, data=josned, headers=smsheader)
print(verify.status_code, verify.reason, verify.text)

这就是结果。。。你知道吗

200 OK
400 Bad Request {"errors":[{"errorCode":"CLSAPI_PRVB_01_2614","errorMessage":"Missing Mandatory field Customer Username or Number"}]}

实际上,必须找到登录响应302,并且必须发送验证。 错误在哪里?我怎么能修好它!!你知道吗


Tags: httpscomapijsonurldatahtmlcode