当前位置:网站首页>基于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
边栏推荐
- CVPR 2022 | common 3D damage and data enhancement
- Redis唯一ID生成器的实现
- Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
- Duchefa丨D5124 MD5A 培养基中英文说明书
- Propping of resources
- Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
- 研學旅遊實踐教育的開展助力文旅產業發展
- 挖财商学院给的证券账户安全吗?可以开户吗?
- 教你自己训练的pytorch模型转caffe(二)
- 1. Strengthen learning basic knowledge points
猜你喜欢

鸿蒙os第四次学习

Duchefa p1001 plant agar Chinese and English instructions

Analysis of steam education mode under the integration of five Education

Duchefa low melting point agarose PPC Chinese and English instructions

Duchefa丨低熔点琼脂糖 PPC中英文说明书

Which is the best online collaboration product? Microsoft loop, notion, flowus

1. Strengthen learning basic knowledge points

10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践

Interpreting the daily application functions of cooperative robots

Duchefa丨P1001植物琼脂中英文说明书
随机推荐
Applet page navigation
Frequent MySQL operations cause table locking problems
Which securities is better for securities account opening? Is online account opening safe?
Duchefa丨MS培养基含维生素说明书
Leetcode (695) - the largest area of an island
Duchefa cytokinin dihydrozeatin (DHZ) instructions
渗透创客精神文化转化的创客教育
sql系列(基础)-第二章 限制和排序数据
CVPR 2022 | common 3D damage and data enhancement
Fundamentals - configuration file analysis
教你自己训练的pytorch模型转caffe(二)
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
解析创客教育的知识迁移和分享精神
教你自己训练的pytorch模型转caffe(三)
Nprogress plug-in progress bar
教你自己训练的pytorch模型转caffe(一)
Chemical properties and application instructions of prosci Lag3 antibody
ClickHouse 复制粘贴多行sql语句报错
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动