在公司访问外网的时候需要经过代理。

Linux

配置临时代理

打开控制台,执行以下代码

export https_proxy="https://company.com.:8080"
export http_proxy="http://company.com.:8080"

随后就可以执行需要连接外网的命令,如:

  • go install
  • npm install
  • git clone

配置永久代理

编辑文件/etc/profile,增加如下两行
打开控制台,执行以下代码

export https_proxy="https://company.com.:8080"
export http_proxy="http://company.com.:8080"

然后执行

source /etc/profile

Conda

修改%UERPROFILE%/.condarc(Windows)~/.condarc(Linux),在原有的配置下面添加如下内容

proxy_servers:
  http: http://company.com.:8080
  https: https://company.com.:8080

Python

配置全局代理

在执行其它代码前,先执行以下代码:

from os import environ
environ['http_proxy']="http://company.com.:8080"
environ['https_proxy']="https://company.com.:8080"

配置局部代理

在需要使用代理的地方使用proxies参数

requests.get(
    "https://aa.com/",
    proxies={
        "https": "https://company.com.:8080",
        "http": "http://company.com.:8080",
    },
)