zoukankan      html  css  js  c++  java
  • Python requests 指定网卡ip发出请求

    当有多个网卡时,request.post 会使用默认网卡发出请求,有时需要改为指定网卡。

    可用如下方式:

    from requests_toolbelt.adapters import source
    
    s = requests.Session()
    new_source = source.SourceAddressAdapter('127.0.0.1') #指定网卡信息
    s.mount('http://', new_source)
    s.mount('https://', new_source)
    s.trust_env=False #禁用系统的环境变量,在系统设置有代理的时候可用用此选项禁止请求使用代理
    response = s.post(url=url, headers=headers, data = payload)

    补充禁用代理访问方法:

    两种方式:
    s = requests.Session()
    s.trust_env = False
    response = session.get('url')
    或者:
    proxies = { "http": None, "https": None}
    requests.get("url", proxies=proxies)
    都可以绕过系统设置的代理
  • 相关阅读:
    link和@import区别
    常用的正则表达式
    virtual dom
    git常用命令
    系统管理与进程命令
    Shell 命令
    软件安装命令
    vim 详解
    网络命令
    帮助与用户管理命令
  • 原文地址:https://www.cnblogs.com/binw/p/13502184.html
Copyright © 2011-2022 走看看