当前位置:网站首页>基于flask写一个接口
基于flask写一个接口
2022-07-05 20:49:00 【vzhb】
背景:
由于et项目吃cookie进行爬虫,我不想手动更新cookie,于是建立了一个cookie线程池。一台云服务器专门自动生产cookie,然后作为接口服务器,另一台在客户端get获取cookie。
或者 这个方法也行,两台服务器直接共享文件夹,1对1通信。
-------------------------------切割线----------------------------------------
注意事项:
设置ip和端口号,以及服务器的公网ip和端口号开放。下面的内网测试。
接口服务端:
from flask import Flask,request
import json
app=Flask(__name__)
# 只接受get方法访问
@app.route("/test",methods=["GET"])
def check():
# 默认返回内容
return_dict= {'return_code': '200', 'return_info': '处理成功', 'result': False}
# 判断入参是否为空
get_data=request.args.to_dict()
if ('name' not in get_data) or ('num' not in get_data):
return_dict['return_code'] = '5004'
return_dict['return_info'] = '请求参数错误'
return json.dumps(return_dict, ensure_ascii=False)
# 获取传入的params参数
name=get_data.get('name')
num=get_data.get('num')
# 对参数进行操作
return_dict['result']=tt(name,num)
return json.dumps(return_dict, ensure_ascii=False)
# 功能函数
def tt(name,num):
result_str="%s申请%s个cookie" %(name,num)
return result_str
if __name__ == "__main__":
#192.168.1.225
app.run(debug=False,host='0.0.0.0')客户端:
网页直接get拿返回值。如图1和图2,分别为空参和正常参数


其中ip和端口号可以自己设置,0.0.0.0是本机ip
边栏推荐
- Duchefa cytokinin dihydrozeatin (DHZ) instructions
- 10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
- go 文件路径操作
- Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
- 14、Transformer--VIT TNT BETR
- Cutting edge technology for cultivating robot education creativity
- 手机开户股票开户安全吗?我家比较偏远,有更好的开户途径么?
- 1. Strengthen learning basic knowledge points
- 线程池的使用
- Implementation of redis unique ID generator
猜你喜欢

小程序全局配置

XML建模

ProSci LAG-3 重组蛋白说明书

鸿蒙os第四次学习

Interpreting the daily application functions of cooperative robots

2.8 basic knowledge of project management process

教你自己训练的pytorch模型转caffe(三)

When steam education enters personalized information technology courses

Analyze the knowledge transfer and sharing spirit of maker Education

Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
随机推荐
Abnova blood total nucleic acid purification kit pre installed relevant instructions
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
Web Service简单入门示例
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
台风来袭!建筑工地该如何防范台风!
线程池的使用
AI 从代码中自动生成注释文档
Which securities is better for securities account opening? Is online account opening safe?
How to renew NPDP? Here comes the operation guide!
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Duchefa丨MS培养基含维生素说明书
Leetcode (695) - the largest area of an island
研学旅游实践教育的开展助力文旅产业发展
Nprogress plug-in progress bar
Analysis of steam education mode under the integration of five Education
Clear app data and get Icon
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
【UE4】UnrealInsight获取真机性能测试报告
ts 之 类的简介、构造函数和它的this、继承、抽象类、接口
MySQL fully parses json/ arrays