python requests_toolbelt模块传输csv文件
2022/4/20 12:42:33
本文主要是介绍python requests_toolbelt模块传输csv文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
需求:测试导入相机信息功能,文件为csv格式
代码实现:
点击查看代码
import os import requests from urllib import parse from requests_toolbelt import MultipartEncoder from utils.handle_yaml import test_info from utils.log_record import logger env1 = test_info.env_info("env1") file = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "test_data", "upload_cameraInfo.csv") class TestUploadCameraInfo(object): """相机信息信息""" def test_upload_camera_info_succs(self, login): # 导入相机 env1["headers"]["accessToken"] = login res_project = requests.get(parse.urljoin(env1["base_url"], "/api/project/query"), headers=env1["headers"]).json() site_id = res_project.get("data").get("siteId") url = parse.urljoin(env1["base_url"], "/api/camera/upload_camera_info/%s" % site_id) logger(url=url, method="POST") # 数据组装 data = MultipartEncoder(fields={"file": ("upload_cameraInfo.csv", open(file, "rb"), "text/csv")}) # 重写Content-Type env1["headers"]["Content-Type"] = data.content_type logger(headers=env1["headers"]["Content-Type"], data=data) res = requests.post(url, headers=env1["headers"], data=data).json() logger(response=str(res)) exp_data = { "code": 0, "data": {}, "message": "success" } assert res == exp_data
这篇关于python requests_toolbelt模块传输csv文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-14用Python校准市场组合模型:贝叶斯先验的妙用
- 2025-01-14每个数据科学家都必须牢记的10个Python函数
- 2025-01-13python项目部署
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南