Python3 设置 profile 环境变量

服务器环境 centos7.3 ,由于服务器上profile设置了代理

Python3 设置 profile 环境变量

代理仅限访问一些限定列表的A类网站(大公司你们懂的),这时,我需要在我的 Python 脚本中访问 不在A类列表中的 某 B 网站 ,就会因为代理限制的原因 无法访问B网站。
Python3 设置 profile 环境变量

总不能每次都运行脚本前,都去修改 profile 文件 删除代理吧?

Python3 设置 profile 环境变量

在 python 中删除代理 / 修改环境变量

  1. OS模块 system (Failed)
    Python3 设置 profile 环境变量

发现依然是拒绝访问,说明不能通过这种方式(在python 脚本中通过 os.system修改环境变量)
Python3 设置 profile 环境变量
2. os.environ (Success)
Python3 设置 profile 环境变量

成功修改环境变量,关闭代理,成功访问 B 。