20 求大佬帮解决,非常感谢!

import requests
import json
import time

#Traceback (most recent call last):
#File, line 58, in <module>       login()
  
#File , line 25, in login
#token_xiaobei = response.json()['token']      KeyError: 'token'

#报以上错误
#求大佬帮忙解决,非常感谢!


def login():
    session = requests.session()
    url_get = 'https://xiaobei.yinghuaonline.com/prod-api/captchaImage'
    response = session.get(url_get)
    uuid = response.json()['uuid']
    showcode = response.json()['showCode']
    url_post = 'https://xiaobei.yinghuaonline.com/prod-api/login'
    # 构建登录字典
    data = {
        "username":"这里是填了的",
        "password":"这里是填了的",
        "code": showcode,
        "uuid": uuid
    }
    response = session.post(url=url_post, json=data)
    token_xiaobei = response.json()['token']
    url_tiwen = "https://xiaobei.yinghuaonline.com/prod-api/student/health"
    headers = {
        # ':method':'POST',
        # ':scheme':'https',
        # ':path':'/prod-api/student/health',
        # ':authority':'xiaobei.yinghuaonline.com',
        # 'accept':'*/*',
        # 'ontent-type':'application/json',
        # 'content-length':'280',
        # 'accept-language':'zh-cn',
        'user-agent': 'iPhone10,6(iOS/13.5.1) Uninview(Uninview/1.0.0) Weex/0.26.0 1125x2436',
        'authorization': token_xiaobei,
        'accept-encoding': 'gzip, deflate, br'
    }
    data = {
        "temperature": "36.3",
        "coordinates": "undefined-陕西省-西安市-雁塔区",
        "location": "108.8814949544271,34.21714735243056",
        "healthState": "1",
        "dangerousRegion": "2",
        "dangerousRegionRemark": "",
        "contactSituation": "2",
        "goOut": "1",
        "goOutRemark": "",
        "remark": "",
        "familySituation": "1"
    }
    response = requests.post(url=url_tiwen, headers=headers, json=data)
    print(response.text)


if __name__ == '__main__':
    login()
请先 登录 后评论

1 个回答

小斌

兄弟,你前面调用了一下json(),你可以看看返回的数据里有没有'token'的key哦!据我猜测,你返回的数据没有'token'造成的错误!

请先 登录 后评论