《Python 常见问题》
1. ProxyError:系统代理(LANTER)未启动
报错现象:urllib3.connection 无法建立到代理连接 —— Connection refused。
原因:电脑设置了系统代理(如 Lantern),但代理软件没有启动。
排查代理:
import requests
print(requests.utils.get_environ_proxies('http://www.google.com'))
# {'a': 'http://127.0.0.1:54796', 'b': 'http://127.0.0.1:54796'}
解决:系统偏好设置 → 网络 → 高级 → 代理 中取消勾选「Web 代理」和「安全 Web 代理」。
2. 写中文字符到文件时报错
在 open() 时显式指定 encoding='utf8':
s = '中文'
with open('test.txt', 'w', encoding='utf8') as f:
f.write(s)
3. 沙箱的实现机制
沙箱通常通过受限的执行环境(如 exec/eval 的受限名字空间 + 资源限制)来实现。具体实现细节待补充。
阅读 —
·
全站 —