当前位置:网站首页>基于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
边栏推荐
- Abnova cyclosporin a monoclonal antibody and its research tools
- 获取前一天的js(时间戳转换)
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
- Clear app data and get Icon
- Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
- The Chinese Academy of Management Sciences gathered industry experts, and Fu Qiang won the title of "top ten youth" of think tank experts
- 线程池的使用
- 欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
- Abnova CRISPR spcas9 polyclonal antibody protocol
- Usaco3.4 "broken Gong rock" band raucous rockers - DP
猜你喜欢

ClickHouse 复制粘贴多行sql语句报错

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

Classic implementation of the basic method of intelligent home of Internet of things

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

Specification of protein quantitative kit for abbkine BCA method

XML建模

Fundamentals - configuration file analysis

Duchefa cytokinin dihydrozeatin (DHZ) instructions

Norgen AAV提取剂盒说明书(含特色)

Typhoon is coming! How to prevent typhoons on construction sites!
随机推荐
教你自己训练的pytorch模型转caffe(一)
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
Duchefa low melting point agarose PPC Chinese and English instructions
Hongmeng OS' fourth learning
ts 之 属性的修饰符public、private、protect
Norgen AAV extractant box instructions (including features)
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
2.8、项目管理过程基础知识
Abnova丨 CD81单克隆抗体相关参数和应用
Classic implementation of the basic method of intelligent home of Internet of things
Monorepo管理方法论和依赖安全
3.3、项目评估
挖财商学院给的证券账户安全吗?可以开户吗?
Abnova丨DNA 标记高质量控制测试方案
培养机器人教育创造力的前沿科技
Frequent MySQL operations cause table locking problems
渗透创客精神文化转化的创客教育
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097