【Python】request绑定指定IP

这篇博客介绍了如何在Python中实现request请求时绑定到指定的IPv4地址。首先,讲解了实现source适配器的方法,接着展示了具体的调用示例,并且详细说明了如何通过安装psutil库来获取本机的所有IPv4地址。
摘要由CSDN通过智能技术生成

实现source适配器

#!/usr/bin/env python
# coding=utf-8
# (C) Copyright 2019-2019, sangfor.Co.Ltd. All rights reserved.

"""
requests_toolbelt.source_adapter
================================
This file contains an implementation of the SourceAddressAdapter originally
demonstrated on the Requests GitHub page.
"""
from requests.adapters import HTTPAdapter
from requests.packages.urllib3 import poolmanager


class SourceAddressAdapter(HTTPAdapter):
    """
    A Source Address Adapter for Python Requests that enables you to choose the
    local address to bind to. This allows you to send your HTTP requests from a
    specific interface and IP address.
    Two address formats are accepted. The first is a string: this will set the
    local IP address to the address given in the string, and wi
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值