PriceForecast/测试环境登录接口调试.ipynb
2024-12-05 16:35:37 +08:00

203 lines
6.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "31c0e11d-c87a-4e95-92a0-d1d09625e255",
"metadata": {},
"outputs": [],
"source": [
"from config_jingbo import *\n",
"import requests\n",
"import json\n",
"import datetime"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "83c81b9e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'http://192.168.100.53:8080/jingbo-dev/api/server/login'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"login_pushreport_url\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a058f507",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2b330ee3-c006-4ab1-8558-59c51ac8d86f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'data': {'account': 'api_test',\n",
" 'password': 'ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=',\n",
" 'tenantHashCode': '8a4577dbd919675758d57999a1e891fe',\n",
" 'terminal': 'API'},\n",
" 'funcModule': 'API',\n",
" 'funcOperation': '获取token'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"login_data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "dcb6100a-ed2b-4077-a1a9-361c6cb565f9",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def get_head_auth_report():\n",
" login_res = requests.post(url=login_pushreport_url, json=login_data, timeout=(3, 5))\n",
" text = json.loads(login_res.text)\n",
" print(text)\n",
" if text[\"status\"]:\n",
" token = text[\"data\"][\"accessToken\"]\n",
" return token\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "22c0c7c4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'confirmFlg': False, 'data': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM0MjMwMjQsImp0aSI6IjhjZWE4YWQ4YWU3YTQyMmY4ODkxYWY4N2RhNmFmNGI5In0.Doq76Zh4PWFr6U0ICJsWpcpFX7tALvIadgXKkt_IHTc', 'md5Token': '091cf636ce5a735ef287a312b1c5d410'}, 'status': True}\n"
]
}
],
"source": [
"token = get_head_auth_report()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "12077ead",
"metadata": {},
"outputs": [],
"source": [
"# token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzE5NTkzNjUsImp0aSI6IjRiMjcwNTgzN2YyZDQxOWM4MzQ3NjI2NDQwZDlhZGQzIn0.PPgnoiJt412dJiceqVW8w7qkJFY4s-VqU9z6ZIkpqho'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a7ae21d1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"上传预警信息\n",
"INFO:my_logger:上传预警信息\n",
"预警上传中...\n",
"INFO:my_logger:预警上传中...\n",
"token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM0MjMwMjQsImp0aSI6IjdiNTdhNDUxNWUwOTQzYWZhNWEwYTUxNzllM2Y0MDQ1In0.7KTHvBMEpsRPM9esVdp3MPLz_5WCjuK1vZvwkhbhfy0\n",
"INFO:my_logger:token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM0MjMwMjQsImp0aSI6IjdiNTdhNDUxNWUwOTQzYWZhNWEwYTUxNzllM2Y0MDQ1In0.7KTHvBMEpsRPM9esVdp3MPLz_5WCjuK1vZvwkhbhfy0\n",
"warning_data:{'funcModule': '原油特征停更预警', 'funcOperation': '原油特征停更预警', 'data': {'WARNING_TYPE_NAME': '特征数据停更预警', 'WARNING_CONTENT': '2024-12-05有34个停更', 'WARNING_DATE': '2024-12-05'}}\n",
"INFO:my_logger:warning_data:{'funcModule': '原油特征停更预警', 'funcOperation': '原油特征停更预警', 'data': {'WARNING_TYPE_NAME': '特征数据停更预警', 'WARNING_CONTENT': '2024-12-05有34个停更', 'WARNING_DATE': '2024-12-05'}}\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'confirmFlg': False, 'data': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM0MjMwMjQsImp0aSI6IjdiNTdhNDUxNWUwOTQzYWZhNWEwYTUxNzllM2Y0MDQ1In0.7KTHvBMEpsRPM9esVdp3MPLz_5WCjuK1vZvwkhbhfy0', 'md5Token': '33e47710d77c32c7f3db2c83cd2bd621'}, 'status': True}\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"上传预警信息成功\n",
"INFO:my_logger:上传预警信息成功\n"
]
}
],
"source": [
"def upload_warning_data(warning_data):\n",
" token = get_head_auth_report()\n",
" warning_data = warning_data\n",
" headers = {\"Authorization\": token}\n",
" logger.info(\"预警上传中...\")\n",
" logger.info(f\"token:{token}\")\n",
" logger.info(f\"warning_data:{warning_data}\" )\n",
" upload_res = requests.post(url=upload_warning_url, headers=headers, json=warning_data, timeout=(3, 15))\n",
" if upload_res:\n",
" return upload_res\n",
" else:\n",
" logger.info(\"预警上传失败\")\n",
" return None\n",
"\n",
"\n",
"logger.info(f'上传预警信息')\n",
"try:\n",
" warning_date = datetime.datetime.now().strftime('%Y-%m-%d')\n",
" content = f'{warning_date}有34个停更'\n",
" warning_data['data']['WARNING_DATE'] = warning_date\n",
" warning_data['data']['WARNING_CONTENT'] = content\n",
" upload_warning_data(warning_data)\n",
" logger.info(f'上传预警信息成功')\n",
"except Exception as e:\n",
" logger.error(f'上传预警信息失败:{e}')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}