avatar
Articles
292
Tags
211
Categories
0

karr's blog
Search

karr's blog

使用 aiohttp & asyncio 实现协程并发下载
Created2024-05-30
协程并发下载12345678910111213141516171819202122232425import aiohttpimport asynciourls = [ "https://www.baidu.com", "https://www.baidu.com", "https://www.baidu.com",]async def async_download(url, idx): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: with open(f"{time.time()}.html", "wb") as f: f.write(await resp.content.read()) print(f"download {idx&# ...
FastAPI如何返回文件字节流
Created2024-05-29
在 FastAPI 中,返回文件字节流的主要方式包括使用 StreamingResponse 和 FileResponse。这两者都可以用于返回二进制数据,例如图像文件。 StreamingResponse: 适用于以流式方式发送数据,对于大型文件特别有用,因为它允许在数据生成时就开始发送,而不必等到整个数据集都可用。1234567891011import iofrom fastapi.responses import StreamingResponse@app.get("/get_demo_image")def get_demo_image(): image_data = open("face.png", "rb").read() return StreamingResponse( content=io.BytesIO(image_data), media_type="image/png" ) FileResponse: 适用于返回文件,可以从文件系统路径中 ...
python 处理图片去重
Created2024-05-28
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455def process_file(img_path): """ 处理图片去重 """ try: phasher = PHash() # 生成图像目录中所有图像的二值hash编码 encodings = phasher.encode_images(image_dir=img_path) # print(encodings) # 对已编码图像寻找重复图像 duplicates = phasher.find_duplicates(encoding_map=encodings) # print(duplicates) only_img = [] # 唯一图片 like_img = [] ...
解决 argparse 获取参数与通过 uvicorn 启动时冲突问题
Created2024-05-24
问题描述产生冲突的原因是因为 uvicorn 启动时候会解析命令行参数,而 argparse 也会解析命令行参数,导致冲突。具体表现为,当使用 uvicorn 启动时候,argparse 获取不到参数。 即在代码中如果在启动了的 uvicorn 程序中调用了sys.argv[1:], 则会报错在 argparse 中的参数列表初始化中有这么一段代码,也是导致报错的原因 1234567def parse_known_args(self, args=None, namespace=None): if args is None: # args default to the system args args = _sys.argv[1:] else: # make sure that args are mutable args = list(args) 解决方案在初始化 argparse 时候,传入参数 [] 即可解决问题 12parser = argparse.ArgumentParser(add_help=add_h ...
通过 dockerfile 部署 opencv-python 相关时候需要引入的依赖库
Created2024-05-24
12RUN apt-get updateRUN apt-get install ffmpeg libsm6 libxext6 -y 完整的一个python37的dockerfile123456789101112FROM python:3.7RUN apt-get updateRUN apt-get install ffmpeg libsm6 libxext6 -yCOPY Makefile requirements.txt ./RUN make installCOPY . ./EXPOSE 8080CMD ["make", "run"]
python 通过 os 更改代码运行目录
Created2024-05-23
123import osos.chdir("../") # 修改当前工作目录print(os.getcwd()) # 获取当前工作目录
Chrome浏览器中使用JavaScript自动下拉刷新页面
Created2024-05-22
在控制台中输入以下代码,可以自动下拉刷新页面1234567891011121314// 设置一个时间间隔(例如1000毫秒)var scrollInterval = 1000;// 创建一个定时器,每隔一定时间执行页面滚动var scrollDownInterval = setInterval(function () { // 滚动到当前页面的最底部 window.scrollTo(0, document.body.scrollHeight); // 如果需要的话,可以在这里添加一些条件来停止滚动 // 例如,可以根据滚动次数或页面特定元素的出现来中断滚动}, scrollInterval);// 若要停止滚动,可以使用以下代码// clearInterval(scrollDownInterval);
vue History 模式部署 nginx 访问其他页面出现 404 解决
Created2024-05-21
官方介绍:https://v3.router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90 在 nginx 加入以下配置即可解决:123location / { try_files $uri $uri/ /index.html;} try_files指令介绍1234567891011121314语法:try_files file ... uri(格式1) 或 try_files file ... = code(格式2)默认值:无作用域:server location解释说明:按指定的file顺序查找存在的文件,并使用第一个找到的文件进行请求处理;查找路径是按照给定的root或alias为根路径来查找的;如果给出的file都没有匹配到,则会进行一个内部重定向到最后一个参数给定的uri,就是新的location匹配;只有最后一个参数可以引起一个内部重定向,之前的参数只设置内部URI的指向;最后一个参数是回退U ...
vue3 配置 404 捕获的方式
Created2024-05-19
使用这种方式会报错1234567891011export const mainOutRoutes: AppRouteModule[] = [ { path: '*', // 不识别的path自动匹配404 name: 'PageNotExist', component: () => import('@/views/sys/exception/404.vue'), meta: { title: 'PageNotExist', ignoreAuth: true } }]; 正确的方式1234567891011export const mainOutRoutes: AppRouteModule[] = [ { path: '/:catchAll(.*)', // 不识别的path自动匹配404 ...
用css实现文字字体颜色渐变
Created2024-05-18
123456/*实现文字颜色从红到黄的线性渐变效果*/.gradient-text { background: linear-gradient(to right, #ff0000, #ffff00); /*设置渐变的方向从左到右 颜色从ff0000到ffff00*/ -webkit-background-clip: text; /*将设置的背景颜色限制在文字中*/ -webkit-text-fill-color: transparent; /*给文字设置成透明*/}
1…8910…30
avatar
karr
世界那么大,我想去看看。
Articles
292
Tags
211
Categories
0
gitee
Announcement
This is my Blog
Recent Post
python 使用线程池来同时执行多个函数2025-07-23
获取 A 股全部历史数据保存到本地2025-07-22
What are AI Agents?2025-07-21
Hello, 极简AES!2025-07-20
Git报错: Failed to connect to github.com port 443 解决方案2025-03-30
Tags
memory_profiler mysqlclient react-error utils OTP io多路复用 importlib postMessage 字典 救猫咪 数据库 text npm 协程 react-warning git-lfs Artificial Intelligence vue-router Android 前端 变现 Homebrew commit message 重复数据 动态口令 Next-key lock stopPropagation ONLY_FULL_GROUP_BY react-fragment-error-message 代码 口罩检测系统 react-props-warning-message 远程仓库 FastAPI eslint es6 GROUP BY 搜索引擎 md5 react-text-error-message
Archives
  • July 20254
  • March 20256
  • February 20252
  • January 20253
  • November 20242
  • October 20243
  • September 20247
  • August 202410
Info
Article :
292
UV :
PV :
Last Update :
©2024 - 2025 By karr
Framework Hexo|Theme Butterfly
Search
Loading the Database