[paramiko] SSHClient.exec_command , ChannelException: Administratively prohibited

James Bardin jbardin at bu.edu
Thu Dec 20 11:19:56 PST 2007


thk wrote:
> Hello.
> I am using paramiko.SSHClient in a python application I am building.  I 
> am issuing "cd" commands but it seems that SSHClient does not keep the 
> session open so if I "cd"  to another directory and issue "pwd" after , 
> I am again in my home directory .
> I mean every command is like connecting again and being in the ~ directory.
> if I issue a command like " cd dir; pwd" then I see from the output of 
> pwd that it has changed directory to dir.
> But not if I do :
> SSHClient.exec_command("cd dir")
> SSHClient.exec_command("pwd").
>   
exec_command opens a new channel for each command. From 
channel.exec_command:
" When the command finishes executing, the channel will be closed and
        can't be reused.  You must open a new channel if you wish to execute
        another command."

You probably want to look at SSHClient.invoke_shell(self, term='vt100', 
width=80, height=24) for an interactive shell.

> Also:
> In another situation I am connecting with sshclient and then I issue 
> commands
> on the remote host, at every 5000 milliseconds interval.
>
> After the 10th or so time ,
> paramiko sshclient raises an exception:
>
> /  File "/usr/lib/python2.5/site-packages/paramiko/client.py", line 314, 
> in exec_command
>     chan = self._transport.open_session()
>   File "/usr/lib/python2.5/site-packages/paramiko/transport.py", line 
> 595, in open_session
>     return self.open_channel('session')
>   File "/usr/lib/python2.5/site-packages/paramiko/transport.py", line 
> 696, in open_channel
>     raise e
> ChannelException: Administratively prohibited
>   
I think that's the server throttling your number of channels.
You either need to maintain an open channel for subsequent commands, or 
send everything as one command.

Take a look at interactive.py in the demos folder, and invoke_shell() in 
both client.py and channel.py


-jim




More information about the paramiko mailing list