Skip to content

[BUG] - AttributeError when calling .exec_command() on a SSHClient which hasn't been .connect()ed yet #2600

Open

Description

@calestyo

Are you using paramiko as a client or server?

Client

What feature(s) aren't working right?

Something else

What version(s) of paramiko are you using?

4.0.0

What version(s) of Python are you using?

3.13.12

What operating system and version are you using?

Debian unstable

If you're connecting as a client, which SSH server are you connecting to?

No response

If you're using paramiko as part of another tool, which tool/version?

No response

Expected/desired behavior

Hey.

When exec_command() is called on a SSHClient object which hasn't been .connect()ed yet, one get's a rather ambiguous AttributeError:

AttributeError: 'NoneType' object has no attribute 'open_session'

This is because of:
https://github.com/paramiko/paramiko/blob/main/paramiko/client.py#L558

which contains no check whether the client has even already been connected.

It would be nice if instead it could give one of Paramiko's exceptions with a useful message, which a failing call to exec_command() does, when e.g. there had already been a connection, but that got interrupted.

Thanks,
Chris.

Actual behavior

see above

How to reproduce

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions