Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unimplemented method #93

Open
et-ent opened this issue Sep 8, 2021 · 8 comments
Open

Unimplemented method #93

et-ent opened this issue Sep 8, 2021 · 8 comments

Comments

@et-ent
Copy link

et-ent commented Sep 8, 2021

I am trying to connect to a cisco style switch to collect some data about it to show on a screen. First the code would hang and I tracked that down and resolved it by telling it to use a minimal shell. It gets past the login and throws an error of "Unimplemented method!" with an error code of 255. I can ssh into the same switch using the same credentials and execute the same command and get back a proper response.

I have used this same code to connect to a typical linux machine (with a similar command) and that worked fine.

Any ideas on where that error is coming from? (Sample of my code below)

shell = spur.SshShell( hostname=ssh_host, username=ssh_username, password=ssh_password, port=ssh_port, missing_host_key=spur.ssh.MissingHostKey.accept, shell_type=spur.ssh.ShellTypes.minimal, )
c = ["show", "clock"]
print(c)
results = shell.run(c)

I expect it to return something along the lines of:
16:04:40 MDT Wed Sep 08 2021

@mwilliamson
Copy link
Owner

Could you post a full stack trace?

@et-ent
Copy link
Author

et-ent commented Sep 9, 2021

Traceback (most recent call last):
File "/home/eric/.local/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 389, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/eric/.local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in call
return await self.app(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/applications.py", line 111, in call
await self.middleware_stack(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc from None
File "/home/eric/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/middleware/authentication.py", line 48, in call
await self.app(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
raise exc from None
File "/home/eric/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/routing.py", line 566, in call
await route.handle(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/routing.py", line 376, in handle
await self.app(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/routing.py", line 566, in call
await route.handle(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
response = await func(request)
File "/home/eric/.local/lib/python3.8/site-packages/starlette/authentication.py", line 69, in async_wrapper
return await func(*args, **kwargs)
File "/projects/entrypoint/ssh-api/app/./ssh.py", line 54, in ssh_v1
results = shell.run(c)
File "/home/eric/.local/lib/python3.8/site-packages/spur/ssh.py", line 172, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "/home/eric/.local/lib/python3.8/site-packages/spur/ssh.py", line 390, in wait_for_result
self._result = self._generate_result()
File "/home/eric/.local/lib/python3.8/site-packages/spur/ssh.py", line 398, in _generate_result
return results.result(
File "/home/eric/.local/lib/python3.8/site-packages/spur/results.py", line 11, in result
raise result.to_error()

@mwilliamson
Copy link
Owner

That stack trace doesn't seem to match up with the error of "Unimplemented method!". Could you post the exception and message as well? i.e. the lines following the ones you've just posted.

@mwilliamson
Copy link
Owner

mwilliamson commented Sep 9, 2021

Actually, come to think of it, I'm not sure that error is coming from spur: I was thinking the error was coming from an unimplemented method in the minimal shell type, but that's not the error that gets raised in that circumstance. Based on the stack trace, spur is invoking the given command, and that command is producing the error you're seeing.

@et-ent
Copy link
Author

et-ent commented Sep 9, 2021

Here is the contents of the results that I get back.

spur.results.RunProcessError: return code: 255
stderr output: b'Unimplemented method!\n'

The command I am issuing is "show clock". I have manually logged onto the same device that the script is logging into using the same credentials and issued the same command it and gives me an output.

So it sounds like I can't use spur than because if I don't use the minimal shell then the script hangs when it tries to execute the command. And if I use the minimal shell that I get the error.

@mwilliamson
Copy link
Owner

One thing worth checking would be how the default shell on your target handles escaping. Spur uses single quotes to escape commands.

@et-ent
Copy link
Author

et-ent commented Sep 15, 2021

Thank you for you assistance. I asked the manufacture of the switch for some help as well. They ended up providing this as part of their response but I don't completely understand it but maybe you do.

Your script is exec type. The switch supports shell-type execution. The exec request will go directly to the start shell, but the switch blocked this kind of execution method, so an error would be reported after the script is executed.

They provided a script that shows how to do it in python. I don't know if this kind of shell is possible but this is the sample code that demostrate it working with their switch.

import time
import paramiko
t = paramiko.Transport(('192.168.1.100',22))
t.connect(username='admin', password='admin')

c = t.open_session()
c.settimeout(15)
c.get_pty()
c.invoke_shell()
c.send('show clock \r')
time.sleep(5)

str = c.recv(65535)
print(str)
t.close()

@mwilliamson
Copy link
Owner

If the above works, then my guess would still be that the problem is the escaping that Spur does. If that's the case, you could either implement your own shell with the correct escaping, or just use paramiko with the code above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants