We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用hrequests指定哪个网口发送请求该怎么写?
比如使用requests指定网口发送请求:
class BindToInterfaceAdapter(HTTPAdapter): def init(self, iface, *args, **kwargs): self.iface = iface super().init(*args, **kwargs)
def init_poolmanager(self, *args, **kwargs): kwargs['socket_options'] = [ (socket.SOL_SOCKET, socket.SO_BINDTODEVICE, self.iface.encode()) ] return super().init_poolmanager(*args, **kwargs)
def fetch_main_page():
interface = 'eno4'
session = requests.Session() session.mount('http://', BindToInterfaceAdapter(interface)) session.mount('https://', BindToInterfaceAdapter(interface)) resp = session.get(url=url, timeout=30)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
用hrequests指定哪个网口发送请求该怎么写?
比如使用requests指定网口发送请求:
class BindToInterfaceAdapter(HTTPAdapter):
def init(self, iface, *args, **kwargs):
self.iface = iface
super().init(*args, **kwargs)
def fetch_main_page():
选择你希望使用的网卡,比如 eth1
interface = 'eno4'
创建一个会话,绑定到指定的网卡接口
The text was updated successfully, but these errors were encountered: