Skip to content

Any way to bind specific network interface? #5504

Answered by webknjaz
june9713 asked this question in Q&A
Discussion options

You must be logged in to vote

I believe you should be able to specify a custom TCPConnector instance with a local_addr set. For example:

import aiohttp


local_address = `localhost`, 12345
tcp_connector = aiohttp.TCPConnector(local_addr=local_address)

async with aiohttp.ClientSession(connector=tcp_connector) as http_session:
    async with http_session.get("https://google.com") as http_response:
        print(await http_response.text())

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@june9713
Comment options

@Yuribtr
Comment options

@june9713
Comment options

@Yuribtr
Comment options

Answer selected by webknjaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #5503 on February 27, 2021 18:51.