0

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!

Jay
  • 458
  • 1
  • 5
  • 9
  • 1
    https://stackoverflow.com/search?q=WinError+10013 -- have you searched those for hints? – Ulrich Eckhardt Apr 15 '22 at 15:48
  • All signs point to firewall / security settings, but I am trying to understand why Python would be blocked, but not puTTY or other programs. I've tried converting to .EXE using both auto-py-to-exe and Nuitka. Both created .EXEs that ran, but the WinError: 10013 remains. I observed that if I turned off networking, I get a "Can't Find Host" error instead of the Forbidden Access Permissions error. So I assume it has to do with how Python creates the socket vs other programs - it's not about an actual port block. Could anyone explain the differences that are going on behind the scenes? – Jay Apr 20 '22 at 15:28
  • @Ulrich Eckhardt, Thank you. I have read a whole bunch of posts about the 10013 error and nearly all of them infer a firewall issue or otherwise blocked / in-use port. While I'm sure it IS firewall or security related, it is not the address or port that is being blocked as I can get access just fine from other programs. I believe this is related specifically to how Python creates the socket connection, or perhaps just permissions on how Python Interpreter runs or something. – Jay Apr 20 '22 at 15:36
  • Can you add the full backtrace? Also, where exactly does that error happen in your code, is it really in the last line? – Ulrich Eckhardt Apr 20 '22 at 15:48
  • I added the traceback to my original post (comment char limit). The code I'm showing is all that's inside the function "sendBarsRouteCmd" -so when I click the Tkinter button, it simply calls that function (ultimately I want to do more, but this is my test script). When run on a different laptop with a physical Ethernet connection directly to the device I'm trying to control, it connects, executes the command and everything works. Its the machine that connects over VPN (the laptop I will want to run this little application from in production) where I get the error. Thx! – Jay Apr 21 '22 at 01:15
  • I'm halfway sure that is not the traceback from the code you have above. Please [edit] your question to contain a [mcve] and the full traceback/output it produces. – Ulrich Eckhardt Apr 21 '22 at 05:59
  • HI, sorry for the delay... I have Edited my post to show the entire code of my program. It shows the Tkinter stuff and the buttons I am using to call my telnet functions. The traceback is definitely from running this script. (The only thing I changed upon pasting above is the IP address - that is not the real IP address of my device.) – Jay Apr 24 '22 at 17:26
  • If you call `sendBarsRouteCmd()` without the Tk UI and a click to the button, it does work, right? If that fails as well, you haven't extracted a [mcve] from your code. Please carefully study that link! – Ulrich Eckhardt Apr 24 '22 at 17:36
  • Oops, forgot the minimally reproducible part :-) Just changed updated my post from a test I just conducted. This is about as basic as I can see: makes the connection, sends some commands to make a route change. It still does NOT work from the Laptop I'd like to use it on (over company VPN) but works just fine from my other laptop - the one I wrote it on - when connected directly to the video device. I've asked our Service Desk about it and they tell me they aren't aware of any specific thing that should be blocking the script from working. (Which is not to say there isn't something.) – Jay Apr 24 '22 at 18:22

0 Answers0