登录Python

import requests

# 登录 Dmingo 账号1234567@h
r_login = requests.post(
url="https://cloud.huaxiaerp.vip/jshERP-boot/user/login",
json={"loginName": "Dmingo", "password": "b678d1268290255da69d7f3ebf68d4cf"}
)
# 判断是否成功
print(r_login.status_code)
print(r_login.json())
# 命名login_result 为r_login.json()
login_result = r_login.json()

login_result_data = login_result.get("data")
print("token" in login_result_data.keys())
# 如果成功,把token取出来,保存到ERP_token

erp_token = login_result_data.get("token")
user_name = login_result_data.get("user").get("loginName")
print(erp_token)
print(user_name)
# 选中加引号, 就是两边加引号

# 请求采购和销售统计接口,请求的时候,erp_token作为请求头“x_access-token"的
r_statistics = requests.get(
url="https://cloud.huaxiaerp.vip/jshERP-boot/depotHead/getBuyAndSaleStatistics",
headers={"x-access-token": erp_token}
)
print(r_statistics.status_code)
print(r_statistics.text)
print(r_statistics.json())

statistics_result = r_statistics.json()
login_satistics_data = statistics_result.get("data")
print(login_satistics_data.get("monthSale"))
print(login_satistics_data.get("monthRetailSale"))
print(login_satistics_data.get("todaySale"))
print(login_satistics_data.get("todayRetailSale"))
print(login_satistics_data.get("todayBuy"))
posted @ 2021-11-21 15:04  icy欢仔  阅读(166)  评论(0编辑  收藏  举报