Koril 最近的时间轴更新
Koril

Koril

V2EX 第 625662 号会员,加入于 2023-04-24 11:27:16 +08:00
今日活跃度排名 2257
关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
问与答  •  Koril  •  8 小时 19 分钟前  •  最后回复来自 Koril
14
2024 年想换台笔记本,老哥们有什么推荐?
计算机  •  Koril  •  115 天前  •  最后回复来自 mmrpeng
123
SpringBoot + JPA 的日志打印问题
问与答  •  Koril  •  2023-08-12 15:40:37 PM  •  最后回复来自 BiChengfei
1
Cron 表达式的一些困惑
问与答  •  Koril  •  2023-06-24 12:41:19 PM  •  最后回复来自 julyclyde
2
请问,如何在 GitHub release 上传软件?
问与答  •  Koril  •  2023-06-12 12:52:28 PM  •  最后回复来自 miaomiao888
2
Koril 最近回复了
8 小时 19 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
补充:Clash 打开系统代理,注册表的 ProxyEnable 变成 1 ,反之为 0 ,urllib.request 的 getproxies_registry() 就是拿这个变量来判断的。
8 小时 27 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
@Abbeyok ok ,我去了解下什么是 tun 模式
8 小时 28 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
@proxytoworld 好的
8 小时 29 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
然后就读取到了 ProxyServer 127.0.0.1:7890 这个键值对,然后在末尾的 else 块中,擅自加上了 https ,最后返回的 proxy 变成了:
{
'ftp': 'ftp://127.0.0.1:7890',
'http': 'http://127.0.0.1:7890',
'https': 'https://127.0.0.1:7890'
}
而 Clash 的代理是 http 代理,所以第三个键值对 https: https://127.0.0.1:7890 会引发 ProxyError 异常,显示无法连接到该代理,正确的键值对应该是 https: http://127.0.0.1:7890 。

这是我目前的一点点理解。
8 小时 40 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
感谢大家的回复,晚上回家翻了下源码,这里我自问自答下:

关于第二个问题:为什么 Windows 开了 Clash 的系统代理,使用 requests 如果不显示的设置 proxies 这个参数(无论是方法传参,还是设置环境变量)就无法请求的问题。

requests 的 sessions 模块的 merge_environment_settings() 方法调用了 Python 自带的 urllib 库中的 request 模块的 getproxies() 方法。

似乎顺序是这样的:方法传参 > 环境变量 > 注册表

如果方法没传参,环境变量也没有设置 http/https_proxy 的话,代码走到以下 elif 块中,去读 Windows 的注册表:

```
elif os.name == 'nt':
def getproxies_registry():
"""Return a dictionary of scheme -> proxy server URL mappings.

Win32 uses the registry to store proxies.

"""
# 省略部分代码
try:
# 查询 win 注册表
internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
proxyEnable = winreg.QueryValueEx(internetSettings,
'ProxyEnable')[0]
if proxyEnable:
# Returned as Unicode but problems if not converted to ASCII
proxyServer = str(winreg.QueryValueEx(internetSettings,
'ProxyServer')[0])
if '=' in proxyServer:
# Per-protocol settings
for p in proxyServer.split(';'):
protocol, address = p.split('=', 1)
# See if address has a type:// prefix
if not re.match('^([^/:]+)://', address):
address = '%s://%s' % (protocol, address)
proxies[protocol] = address
else:
# Use one setting for all protocols
if proxyServer[:5] == 'http:':
proxies['http'] = proxyServer
else:
proxies['http'] = 'http://%s' % proxyServer
proxies['https'] = 'https://%s' % proxyServer
proxies['ftp'] = 'ftp://%s' % proxyServer
internetSettings.Close()


return proxies
```
14 小时 27 分钟前
回复了 Koril 创建的主题 问与答 关于 Clash、curl、 Python pip/requests/httpx 代理的一些困惑
@proxytoworld hhh 抽象么,可能因为我是个初学者,提的问题比较奇怪。
@ampedee 我找了下,应该指的是 backend_type 字段吧,SQL 加个 where backend_type = 'client backend' 数量就对象了。
242 天前
回复了 Koril 创建的主题 计算机 2024 年想换台笔记本,老哥们有什么推荐?
@ZxykM 这个感觉不错。
242 天前
回复了 Koril 创建的主题 计算机 2024 年想换台笔记本,老哥们有什么推荐?
昨天看到,ThinkPad 的 T14p ,好像是板载 32 GB ,感觉有点可惜
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   930 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 323ms · UTC 22:04 · PVG 06:04 · LAX 15:04 · JFK 18:04
Developed with CodeLauncher
♥ Do have faith in what you're doing.