当前位置:网站首页>基於flask寫一個接口
基於flask寫一個接口
2022-07-05 20:50: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
边栏推荐
- 14、Transformer--VIT TNT BETR
- Where is a good stock account? Is online account manager safe to open an account
- 2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
- Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书
- Applet page navigation
- Abbkine BCA法 蛋白质定量试剂盒说明书
- 解析创客教育的知识迁移和分享精神
- Duchefa丨S0188盐酸大观霉素五水合物中英文说明书
- 小程序全局配置
- sql系列(基础)-第二章 限制和排序数据
猜你喜欢
Classic implementation method of Hongmeng system controlling LED
Duchefa丨D5124 MD5A 培养基中英文说明书
Welcome to the game and win rich bonuses: Code Golf Challenge officially launched
Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
Duchefa cytokinin dihydrozeatin (DHZ) instructions
表单文本框的使用(二) 输入过滤(合成事件)
Interpreting the daily application functions of cooperative robots
ProSci LAG-3 重组蛋白说明书
How to make ERP inventory accounts of chemical enterprises more accurate
ClickHouse 复制粘贴多行sql语句报错
随机推荐
Cutting edge technology for cultivating robot education creativity
挖财商学院给的证券账户安全吗?可以开户吗?
[Yugong series] go teaching course in July 2022 004 go code Notes
珍爱网微服务底层框架演进从开源组件封装到自研
Analysis of steam education mode under the integration of five Education
实现浏览页面时校验用户是否已经完成登录的功能
Prosci LAG-3 recombinant protein specification
Frequent MySQL operations cause table locking problems
研學旅遊實踐教育的開展助力文旅產業發展
培养机器人教育创造力的前沿科技
当Steam教育进入个性化信息技术课程
sql系列(基础)-第二章 限制和排序数据
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
Clear app data and get Icon
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
The development of research tourism practical education helps the development of cultural tourism industry
Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
Welcome to the game and win rich bonuses: Code Golf Challenge officially launched
Usaco3.4 "broken Gong rock" band raucous rockers - DP
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel