I'm trying to write an application in Python for controlling a video switcher via Telnet. I can "remote" control the switcher by using simple Telnet commands I can type into PuTTY or other terminal programs (such as SolarPuTTY, and even Telnet Lite on my mobile phone). In addition, I can use the software produced by the manufacturer which also uses telnet behind the scenes. The connection is the IP address of the device and port 9990.
The software doesn't do what I'd like (easily) and text-based telnet commands is even less efficient so I want to make a "control panel" with Python: a screen of preset buttons, click the preset and execute the Telnet commands to make it happen.
I have started programming this in Python using telnetlib but when I try to make a connection, I am getting "[WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions"
I am trying this on a laptop that is connected to our network over VPN. From all the research I've done, it sounds like the issue could be our VPN or Firewall blocking the connection to that port, however I have no trouble connecting to the very same device/connection using PutTTY, SolarPuTTY or the manufacturer's software on the same laptop. I can connect all 3 of these programs simultaneously and they all work just fine. There have been no "special exceptions" made to our VPN / Network / Firewall to allow these programs to communicate. They have just always worked.
So I am wondering:
- If anyone can explain how these other programs connect differently from how Python is attempting to connect that lets them through the blockage?
- Are there any known workarounds that that I can try (eg a "different way" that Python can connect that wouldn't be blocked?
- If anyone has any other suggestions that may be causing the issue that is less obvious (maybe I need to format my address differently? Maybe I am missing a step? - Likely! :-))?
EDIT I left out this important tidbit when I first posted: I am creating a testing my Python on personal laptop that has no firewalls or VPN software or group policy management of any kind and then compiling it into an EXE using auto-py-to-exe. It is the resultant EXE that I am running on the other laptop which is on the company VPN.
UPDATE The code I originally posted does not work and am pasting new code that does work (when run from a different laptop directly connected to the video switcher via Ethernet). When I run it on the company laptop - even when directly connected to the video switcher ( no other network connection, no vpn) I get the same WinError.
Minimal Test Script Example:
from telnetlib import Telnet
import time
data = ""
with Telnet('10.200.200.110',9990, timeout = 5) as tn:
data = data + tn.read_until(b"PRELUDE:\n", timeout = 5).decode('ascii')
print(data)
time.sleep(0.1)
print("ROUTING TV")
tn.write(b"video output routing:" + b"\n")
time.sleep(0.1)
tn.write(b"31 17" + b"\n")
time.sleep(0.1)
tn.write(b"\n")
- There is no login / password - it just connects anonymously
- I have also checked if any ports were blocked using netstat - nothing appears blocked
- I have tried different ports just for good measure - the result is always the same
- Changing host to "localhost" does NOT result in an error
It occurs to me that maybe the restriction that Windows is putting on has something to do with how the EXE file is being run? Perhaps it runs as a different user or something? When I run as Administrator the result is exactly the same.
Thank you, J
Addition: Minimal Example Traceback:
C:\Users\jl\Desktop>telnetBasicTesting.exe
Traceback (most recent call last):
File "telnetBasicTesting.py", line 6, in
File "telnetlib.py", line 218, in init
File "telnetlib.py", line 235, in open
File "socket.py", line 844, in create_connection
File "socket.py", line 832, in create_connection
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
[23304] Failed to execute script 'telnetBasicTesting' due to unhandled exception!