r = {'code': 200, 'body': {'code': 200, 'msg': 'request success', 'data': {'username': 'a***', 'mobile': '132**51', 'companyType': 6, 'token': 'ey**RI', 'companyName': '** Company', 'nickname': 'ab**'}}}
body = r['body']
print(body) # {'code': 200, 'msg': 'request success', 'data': {'username': 'a***', 'mobile': '132**51', 'companyType': 6, 'token': 'ey**RI', 'companyName': '**Company', 'nickname': 'ab**'}}
# Initialize the database object
conn = init_db("db_1")
# Search Results
res_db = conn.fetchone("select mobile from hy_user where username = 'abc'")
print("Database query result is: %s"%res_db)
# Validate the results
user_mobile = body['mobile']
assert user_mobile == res_db['mobile']
Keyerror: ‘mobile’
Because mobile is in the data dictionary of body, change to user_ Mobile = body [‘data ‘] [‘mobile’]
Read More:
- Python: How to Create an Automatic Recording Program
- How to Fix keyerror in Python dictionary lookup
- [Solved] raise KeyError(key) from err KeyError: ‘Dates‘
- The automatic token of Python interface is passed into the header
- Python Pandas Error: KeyError: 0 [How to Solve]
- Python: How to Solve mysqlclient Install Error in Mac
- numpy.concatenate() 253rd; 38169Keyerror: 0 [How to Solve]
- How to Solve wikiextractor Extract Wikipedia Corpus Error
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- [Solved] KeyError: ‘Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘
- How to Solve Pytorch eval Stuck Error
- How to Solve Python Xlwt ValueError: More than 4094 XFs (styles)
- How to Solve Python ImportError: cannot import name UnrewindableBodyError
- odoo Error: KeyError:‘ir.http‘ [How to Solve]
- How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError
- [Solved] PyTorch Lightning Error: KeyError: ‘hidden_states‘
- How to Solve no module fcntl Error in Windows