Python pip 源配置

Python pip 源配置 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/22/python-pip-conf/ 使用阿里云的 pip 源。 支持 https 和 http 1 2 3 4 5 6 7 8 9 mkdir ~/.pip cat > ~/.pip/pip.conf << EOF [global] trusted-host=mirrors.aliyun.com index-url=https://mirrors.aliyun.com/pypi/simple/ EOF mac + venv 在 mac + venv 下, 路径 ~/.pip/pip.conf 中的配置并不生效。 而真正生效的路径是 ~/.config/pip/pip.conf……

阅读全文

Python Keywords: with

Python Keywords: with 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/22/python-keywords-with/ with 是 python 中的一个关键字。 一种更简单的方式实现 try...catch。 例如, 打开文件后获得文件句柄f, 无论执行是否正常都需要关闭句柄。 1 2 3 4 5 6 try: f = open("file.txt", "r") f.write("Hello, World!") finally: f.close() 但是使用 with 关键字, 就可以简单的写成如下 1 2 with open("file.txt", "w") as f: f.write("Hello, World!") with...as 的类实现: ContextManager with……

阅读全文

Python 配置解析: PyYaml

Python 配置解析: PyYaml 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-config-pyyaml/ pyyaml 是 python 中管理 yaml 依赖库。 1 pip install pyyaml 虽然名字叫 pyyaml, 但是在 import 的时候却使用的是 yaml 1 import yaml load 解析 load 支持解析 字符串 文件, 不用预先读取成字符串再解析 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import yaml ### 字符串 info = """ name: tangx age: 20 address: contry: China city: Beijing """ cfg = yaml.safe_load(info) print(cfg) ### 文件 with open("config.yaml",……

阅读全文

Python 日志库: Loguru

Python 日志库: Loguru 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-loguru/ loguru 是一款常用的 python 日志库。 https://loguru.readthedocs.io/en/stable/overview.html 注意: loguru 没有 fatal, 而是 critical 安装 1 pip install loguru 基础使用 1 2 3 4 5 6 7 8 9 10 from loguru import logging as log ## 设置格式 logger.add("file.log", format="{time} {level} {message}", level="INFO") ## 设置 level logger.level("ERROR") # 注意, 不支持小写 logger.info("Hello, World!") logger.critical("This is a critical message!") 装饰器用法 1 2 3 4 @logger.catch def test_logger(x: int): log.info("This is a test logger function!") return 10 / x 绑定额外参……

阅读全文

Python 最小化 Requirements

Python 最小化 Requirements 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-minimum-requirements/ 使用 pip freeze 会把当前环境中的所有依赖包都放到 requirements.txt 中。 使用 pigar 最小化 Requirements 安装 1 pip install pigar 生成 1 pigar generate 使用 pipreqs 最小化 Requirements 安装 1 pip install pipreqs 生成 1 2 3 4 5 6 # 强制覆盖 requiremetns.txt pipreqs --encoding utf-8 --ignore .venv --force # 输出到 os.stdout pipreqs --encoding utf-8 --ignore .venv --print……

阅读全文

Github 配置多账户访问

Github 配置多账户访问 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/15/github-multiple-account/ 当拥有多账户的时候,可能造成账户冲突。 表现为 私有仓库有权限, 但访问时提示没权限或仓库不存在。 1 2 3 4 5 6 7 $ git pull ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 使用 ssh -T 查看账户 1 2 3 $ ssh -T [email protected] Hi tangx! You've successfully authenticated, but GitHub does not provide shell access. 配置 ~/.ssh/config 主……

阅读全文

Aws Authorize Security Group Rules in Command

Aws Authorize Security Group Rules in Command 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/13/aws-authorize-security-group-rules-in-command/ 使用 aws cli 在线文档 aws 命令行工具的 help 不是很方便, 可以使用 Google 搜索在线文档 例如搜索 aws cli authorize-security-group-ingress 为 Security Group 增加规则 Security Group 的规则分为 入口(ingress) / 出口 (engress) 分别对应命令 1 2 authorize-security-group-ingress authorize-security-group-engress 配置方式是一样的, 通常出口规则都是 0.0.0.0/0。 这里以入口规……

阅读全文

Aws Elasticache Redis

Aws Elasticache Redis 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/03/aws-elasticache-redis/ 1. 创建 Redis 服务 AWS 中提供 Redis 的服务是 ElastiCache. 可以根据文档进行创建 创建 Serverless Redis Cache 服务 2. VPC 内部连接 Redis 创建完成后, 配置对应的 SecurityGroup 后, 可以直接在 VPC 内面密码访问。 注意: 连接强制开启 TLS 在集群内启动一个 redis 容器, 使用如下命令 1 2 3 4 5 $ redis-cli --tls -h reids-xxxxx.serverless.region.cache.amazonaws.com -p 6379 redis> set name zhangsan redis> get name "zhangsan" 3.……

阅读全文

Nodejs Prisma Connect DB in Sslmode

Nodejs Prisma Connect Db in Sslmode 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/07/19/nodejs-prisma-connect-db-in-sslmode/ Prisma connect Heroku Database with SSL PrivateLink: https://devcenter.heroku.com/articles/heroku-postgres-via-privatelink External Access with Certs and Key 0. Pre-Test 0.1. Test the Certificate (1) Using TablePlus to test the SSL Certificates. It works. (2) Using psql command to test 1 psql "postgres://${UserName}:${DumpPass123}@{DB_HOST}:5432/{DB_Name}?sslmode=require&sslrootcert=root.crt&sslkey=postgresql.key&sslcert=postgresql.crt" 0.2. Check the Prisma Docs From the Prisma’s docs - Configuring an SSL Connection , it supports PCKS12 only. sslmode=(disable|prefer|require) sslcert=/some/path/ca.pem sslidentity=/some/path/cert.p12 sslpassword={dump_pass} : provide while generating the cert.p12 sslaccept=(strict|accept_invalid_certs) : accept_invalid_certs is required if using the self-signed certficate. 1. download the ssl key and crts download the certificates files add your ip into whitelist 2. convert crt to pem https://stackoverflow.com/questions/4691699/how-to-convert-crt-to-pem openssl x509 -in postgresql.crt -out postgresql.crt.pem -outform PEM 3. convert crt and pem……

阅读全文

Aliyun ACK 集群 Flannel 多路由表故障

Aliyun ACK 集群 Flannel 多路由表故障 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/06/06/aliyun-ack-flannel-network-issue/ 0. 环境 Aliyun ACK 集群 (master 托管) Flannel 网络 多路由表 1. 故障现象 服务从外部访问 相应缓慢, 甚至 超时 kubectl metrics 信息 跨节点的 Pod 网络不通, 但同节点正常。 无妨访问外网 2. 故障原因 当 (1)阿里云 ACK 集群 节点所在的 VPC (2)开启多个路由表 , 且 (3)集群使用 Flannal 网……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它