Python Forum
How to direct python to use a specific network adapter?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to direct python to use a specific network adapter?
#1
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/4700...rk-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.
Reply
#2
Wired vs wireless is outside python's scope.  Is that the error you get without a wired connection?
Reply
#3
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)
Reply
#4
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/2205...es#tab-top
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
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.
Reply
#7
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
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/For...progeneral (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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#9
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.
Reply
#10
Thanks for coming back and letting us know what happened :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wi-Fi Direct Python teodorisss 2 3,759 Aug-14-2020, 07:21 AM
Last Post: teodorisss
  Why Python for Network Programming ashilnayak2 1 2,445 May-18-2020, 09:20 AM
Last Post: DeaD_EyE
  Assistance with Python Network script cscecela 2 4,724 Feb-24-2019, 01:23 AM
Last Post: searching1
  A virtual network to use with python to learn about networking with python? marienbad 0 2,329 Feb-11-2019, 09:20 PM
Last Post: marienbad
  Batch network configuration/ verification task using Python anonyfate 1 3,114 Jul-03-2018, 04:30 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020