Python Forum
How to direct python to use a specific network adapter? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: How to direct python to use a specific network adapter? (/thread-5966.html)



How to direct python to use a specific network adapter? - ormesome - Oct-30-2017

This is a copy of a thread I started on StackOverflow which is getting down voted for being off topic. I regret that I didn't think to ask the good folks here first. https://stackoverflow.com/questions/47007003/how-to-direct-python-to-use-a-specific-network-adapter

Python (3.6) works great on my wired network adapter but I am unable to run pip (or pycurl or urllib) when on the wireless. I receive the following error, which led me to believe that it's proxy related:
Output:
PS C:\Projects> py -m pip install --upgrade pip Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BC58ADF6D8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))': /simple/pip/
But I'm not behind a proxy
Output:
PS C:\Projects> netsh winhttp show pro Current WinHTTP proxy settings: Direct access (no proxy server).
and I know how to set the proxy for pip, pycurl, and urllib.

How do I tell the python environment that I want it to direct all traffic over the wireless adapter instead of the wired adapter?

FYI, I'm always on wireless. The only time I have to connect to the wire is to do python network things.


RE: How to direct python to use a specific network adapter? - nilamo - Nov-02-2017

Wired vs wireless is outside python's scope.  Is that the error you get without a wired connection?


RE: How to direct python to use a specific network adapter? - ormesome - Nov-02-2017

That's the error I get on wireless. When I'm on the wired connection I have no errors.

Given that the issue affects a range of network related python packages I assumed that there was a shared base package that required an environment variable or something to be configured.

I don't have any problems with other applications (IE, powershell, email, etc)


RE: How to direct python to use a specific network adapter? - DeaD_EyE - Nov-02-2017

This is not a Python related problem. I looks like the nameserver is not reachable or the Proxy is not configured right or reachable.
It's the task of the OS to handle this connectivity stuff.

You can set proxy servers as environment variables: https://stackoverflow.com/questions/22059670/how-can-i-set-a-proxy-server-for-gem?answertab=votes#tab-top


RE: How to direct python to use a specific network adapter? - wavic - Nov-02-2017

This is not related to Python. Python just uses an existing connection. Python is in the application layer. It communicates with the system, which is communicating with the drivers and the last one in the chain is the hardware. Try it. Ping the pypi.python.org. Or tracert it


RE: How to direct python to use a specific network adapter? - ormesome - Nov-02-2017

I know you say it's not python, that I should check my proxy, but I don't have a proxy either at home or in the office I'm visiting today.

The OS says that I have a perfectly fine network connection. Python does not agree.

Output:
PS C:\WINDOWS\system32> ping pypi.python.org Pinging prod.python.map.fastly.net [151.101.80.223] with 32 bytes of data: Reply from 151.101.80.223: bytes=32 time=26ms TTL=58 Reply from 151.101.80.223: bytes=32 time=26ms TTL=58 Reply from 151.101.80.223: bytes=32 time=27ms TTL=58 Reply from 151.101.80.223: bytes=32 time=27ms TTL=58 Ping statistics for 151.101.80.223: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 26ms, Maximum = 27ms, Average = 26ms
Output:
PS C:\WINDOWS\system32> tracert pypi.python.org Tracing route to prod.python.map.fastly.net [151.101.80.223] over a maximum of 30 hops: 1 2 ms 1 ms 2 ms 27.122.116.182 2 20 ms 2 ms 2 ms e1-9.br01.b1.bne.au.superloop.com [103.200.13.175] 3 26 ms 28 ms 26 ms Bundle-Ether1.br02.s1.syd.au.superloop.com [103.200.13.179] 4 26 ms 25 ms 26 ms v101.br01.m1.mel.au.superloop.com [103.200.13.197] 5 * 26 ms 26 ms as54113.melbourne.megaport.com [103.26.71.34] 6 26 ms 26 ms 26 ms 151.101.80.223 Trace complete.



RE: How to direct python to use a specific network adapter? - wavic - Nov-02-2017

Try to set up a proxy server for your connection and pass it to pip as option: pip install <packet> --proxy="proxy_server:port"
There is something wrong with your connection. Check which port pip is using check the router NAT.


RE: How to direct python to use a specific network adapter? - sparkz_alot - Nov-02-2017

Perhaps you could post the code you are using that you are using for the connection (between code tags).
If you have access to the router, you should be able to see if the computer is connected to the wired and or wireless port(s). If both adapters are 'Active', try manually disabling the wired adapter manually. Some BIOS's don't allow both wired and wifi at the same time, so you may want to check that.

There is this post https://social.technet.microsoft.com/Forums/en-US/1b2d9ce7-68ad-4fa1-bc2c-eff34b818acf/wifi-and-ethernet-same-time-windows-10?forum=win10itprogeneral (see the last post), just make sure you can undo any changes you make should the need arise.

Again, it would be helpful to see the code you are using to make the connection.


RE: How to direct python to use a specific network adapter? - ormesome - Nov-06-2017

I identified that the http_proxy and https_proxy environment variables for a specific office (the only place I used a wired connection) had been set. Removing those variables has fixed the problem.

I'm a little annoyed that these environment variables somehow trump everything else, but I've learned something new.

Thank you all.


RE: How to direct python to use a specific network adapter? - nilamo - Nov-08-2017

Thanks for coming back and letting us know what happened :)