Re: [Tutor] how to control putty window

2012-12-27 Thread Ufuk Eskici
Hello,

I've installed Paramiko on my PC with Python 2.7.

My code is:
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.connect('10.10.10.10', username='ufuk', password='ufuk')

But I'm getting this error:



Traceback (most recent call last):
  File C:/Users/eufuesk/Desktop/paramiko.py, line 1, in module
import paramiko
  File C:/Users/eufuesk/Desktop\paramiko.py, line 4, in module
ssh = paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'


Anybody familiar with paramiko?


2012/12/20 Prasad, Ramit ramit.pra...@jpmorgan.com

 Ufuk Eskici wrote:
  Hello,
 
  I run this command and opens putty:
 
  import os
  import subprocess
  command = 'c:\Program Files\Putty\putty.exe -ssh
 ufukeskici@10.10.10.10 -pw test
  subprocess.Popen(command)
 
  But then I want to input new commands to this Putty new window. How can
 I do it?
 

 Do you need to control Putty or just SSH to another computer?
 If all you need to SSH then I would recommend using a 3rd
 party module such as Fabric (which relies on Paramiko). Those modules
 will simply SSH significantly. They are Python 2.x but you should
 be able to use Paramiko in 3.x except for SFTP. This link might help
 to install Paramiko if you are using Python 3.
 https://github.com/paramiko/paramiko/issues/16

 If you need to control Putty specifically then I cannot help.


 Ramit


 This email is confidential and subject to important disclaimers and
 conditions including on offers for the purchase or sale of
 securities, accuracy and completeness of information, viruses,
 confidentiality, legal privilege, and legal entity disclaimers,
 available at http://www.jpmorgan.com/pages/disclosures/email.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread Alan Gauld

On 27/12/12 09:36, Ufuk Eskici wrote:


I've installed Paramiko on my PC with Python 2.7.

My code is:
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.connect('10.10.10.10', username='ufuk', password='ufuk')

Traceback (most recent call last):
   File C:/Users/eufuesk/Desktop/paramiko.py, line 1, in module
 import paramiko
   File C:/Users/eufuesk/Desktop\paramiko.py, line 4, in module
 ssh = paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
 


Did paramiko install properly?
Can you access anything in the module?

What happens if you do

 import paramiko
 dir(paramiko)

or

 help(paramiko)

If those didn't work it suggests the install didn't work properly.
If they do work then I don't know what's wrong.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread Ufuk Eskici
It seems it is looking for Paramiko under wrong folder.

 import paramiko

Traceback (most recent call last):
  File pyshell#3, line 1, in module
import paramiko
  File C:/Users/eufuesk/Desktop\paramiko.py, line 3, in module
ssh = paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
 os.chdir(c:\\Python27)


Which directory should I use?


2012/12/27 Alan Gauld alan.ga...@btinternet.com

 On 27/12/12 09:36, Ufuk Eskici wrote:

  I've installed Paramiko on my PC with Python 2.7.

 My code is:
 import paramiko
 import os
 ssh = paramiko.SSHClient()
 ssh.connect('10.10.10.10', username='ufuk', password='ufuk')

 Traceback (most recent call last):
File C:/Users/eufuesk/Desktop/**paramiko.py, line 1, in module
  import paramiko
File C:/Users/eufuesk/Desktop\**paramiko.py, line 4, in module
  ssh = paramiko.SSHClient()
 AttributeError: 'module' object has no attribute 'SSHClient'
  


 Did paramiko install properly?
 Can you access anything in the module?

 What happens if you do

  import paramiko
  dir(paramiko)

 or

  help(paramiko)

 If those didn't work it suggests the install didn't work properly.
 If they do work then I don't know what's wrong.


 --
 Alan G
 Author of the Learn to Program web site
 http://www.alan-g.me.uk/

 __**_
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread Hugo Arts
On Thu, Dec 27, 2012 at 10:53 AM, Ufuk Eskici ufukesk...@gmail.com wrote:

 It seems it is looking for Paramiko under wrong folder.

  import paramiko

 Traceback (most recent call last):
   File pyshell#3, line 1, in module
 import paramiko
   File C:/Users/eufuesk/Desktop\paramiko.py, line 3, in module
 ssh = paramiko.SSHClient()
 AttributeError: 'module' object has no attribute 'SSHClient'
  os.chdir(c:\\Python27)


 Which directory should I use?


The problem is that you have a file named paramiko.py in the current
directory. When python executes an import, it looks first in the list of
built-in modules, and then in a set of directories listed in sys.path. The
first directory in sys.path is always the current directory of the script.
So when you do import paramiko python looks in the current directory,
finds a file called paramiko.py, and imports that happily.

The lesson is that you should never give your python scripts the same as a
module you're using, because then python will be confused about which file
to import, and you'll be confused why your imported module has none of the
names it should have.

Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread Dave Angel
On 12/27/2012 04:53 AM, Ufuk Eskici wrote:
 It seems it is looking for Paramiko under wrong folder.

 import paramiko
 Traceback (most recent call last):
   File pyshell#3, line 1, in module
 import paramiko
   File C:/Users/eufuesk/Desktop\paramiko.py, line 3, in module
 ssh = paramiko.SSHClient()
 AttributeError: 'module' object has no attribute 'SSHClient'
 os.chdir(c:\\Python27)

 Which directory should I use?


Looks to me like you're testing it with a script file called
paramiko.py So when you import paramiko, it's finding your script
instead of the installed paramiko.  Even in the best of times, importing
a module with the same name as your script is problematic.  But in this
case, you're completely masking the actual module.

So rename your script and move it somewhere other than the desktop. 
Start a cmd box (DOS window), and run

c:  cd sourcedir
c:  python mytest.py


Another comment:  when starting a new thread, please use a fresh email
to tutor@python.org.  Don't use reply to an existing message, or your
query can get lost in the noise.  And of course pick a subject line that
matches your query, like  Trouble importing paramiko


-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread ALAN GAULD
It looks like you have named your program paramiko.py? That is hiding the 
module.
Try renaming your script.

BTW its probavbly a bad idea to keepm Python scripts on the Desktop. 
Better to create a folder.


 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




 From: Ufuk Eskici ufukesk...@gmail.com
To: Alan Gauld alan.ga...@btinternet.com 
Cc: tutor@python.org tutor@python.org 
Sent: Thursday, 27 December 2012, 9:53
Subject: Re: [Tutor] how to control putty window
 

It seems it is looking for Paramiko under wrong folder.


 import paramiko


Traceback (most recent call last):
  File pyshell#3, line 1, in module
    import paramiko
  File C:/Users/eufuesk/Desktop\paramiko.py, line 3, in module
    ssh = paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
 os.chdir(c:\\Python27)




Which directory should I use?



2012/12/27 Alan Gauld alan.ga...@btinternet.com

On 27/12/12 09:36, Ufuk Eskici wrote:


I've installed Paramiko on my PC with Python 2.7.

My code is:
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.connect('10.10.10.10', username='ufuk', password='ufuk')


Traceback (most recent call last):
   File C:/Users/eufuesk/Desktop/paramiko.py, line 1, in module
     import paramiko
   File C:/Users/eufuesk/Desktop\paramiko.py, line 4, in module
     ssh = paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
 

Did paramiko install properly?
Can you access anything in the module?

What happens if you do

 import paramiko
 dir(paramiko)

or

 help(paramiko)

If those didn't work it suggests the install didn't work properly.
If they do work then I don't know what's wrong.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-27 Thread Alan Gauld

On 27/12/12 10:32, Dave Angel wrote:


Another comment:  when starting a new thread, please use a fresh email
to tutor@python.org.  Don't use reply to an existing message, or your
query can get lost in the noise.  And of course pick a subject line that
matches your query, like  Trouble importing paramiko


To be fair this is part of the putty thread in that he was suggested 
paramiko as an alternative to controlling putty... It's still part of 
the original problem solution, its just that the original subject was a 
tad too specific.



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-21 Thread Ufuk Eskici
Hello,

I changed my way. This time I'm using plink under Putty.

My python code is:

os.chdir(c:\\Program Files\\Putty)
cmd = plink -ssh -l ufuk10.10.10.10 -pw password
process = subprocess.Popen(cmd)
inputdata=r van
result = process.communicate(inputdata)

But after the successful SSH, I cannot continue, no command runs:
This is the new output after the initial SSH connection:
No data input.

Last login: Fri Dec 21 16:27:
ufuk@home-ubuntu:~$


2012/12/20 Prasad, Ramit ramit.pra...@jpmorgan.com

 Ufuk Eskici wrote:
  Hello,
 
  I run this command and opens putty:
 
  import os
  import subprocess
  command = 'c:\Program Files\Putty\putty.exe -ssh
 ufukeskici@10.10.10.10 -pw test
  subprocess.Popen(command)
 
  But then I want to input new commands to this Putty new window. How can
 I do it?
 

 Do you need to control Putty or just SSH to another computer?
 If all you need to SSH then I would recommend using a 3rd
 party module such as Fabric (which relies on Paramiko). Those modules
 will simply SSH significantly. They are Python 2.x but you should
 be able to use Paramiko in 3.x except for SFTP. This link might help
 to install Paramiko if you are using Python 3.
 https://github.com/paramiko/paramiko/issues/16

 If you need to control Putty specifically then I cannot help.


 Ramit


 This email is confidential and subject to important disclaimers and
 conditions including on offers for the purchase or sale of
 securities, accuracy and completeness of information, viruses,
 confidentiality, legal privilege, and legal entity disclaimers,
 available at http://www.jpmorgan.com/pages/disclosures/email.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-21 Thread Prasad, Ramit
Ufuk Eskici wrote: 
 Hello,
 
 I changed my way. This time I'm using plink under Putty.
 
 My python code is:
 
 os.chdir(c:\\Program Files\\Putty)
 cmd = plink -ssh -l ufuk10.10.10.10 -pw password
 process = subprocess.Popen(cmd)
 inputdata=r van
 result = process.communicate(inputdata)
 
 But after the successful SSH, I cannot continue, no command runs:
 This is the new output after the initial SSH connection:
 No data input.
 
 Last login: Fri Dec 21 16:27:
 ufuk@home-ubuntu:~$

I am not familiar with plink, so I cannot help you. I recommend using
an SSH module which help a lot with all of this. That being said, maybe this 
post will help:
http://code.activestate.com/lists/python-tutor/74807/ 

Also take a look at the subprocess.communicate documentation[1] as 
it says
 Interact with process: Send data to stdin. Read data from stdout and 
stderr, until end-of-file is reached. **Wait for process to terminate**. The 
optional input argument should be a string to be sent to the child process, or 
None, if no data should be sent to the child.
communicate() returns a tuple (stdoutdata, stderrdata).
Note that if you want to send data to the process's stdin, you need to create 
the Popen object with stdin=PIPE. Similarly, to get anything other than None in 
the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too.
 (emphasis added)
This suggests communicate is waiting for the plink to end? Also, you
should probably pass in a pipe so that you can send data more than
once.  Note, I am not familiar with subprocess so YMMV.

[1]http://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate



Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-21 Thread Ufuk Eskici
I used this code:

os.chdir(c:\\Program Files\\Putty)
cmd = plink -ssh -l ufuk 10.10.10.10 -pw password
process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate ()

After running this code, just one black cmd screen appears, but it frezzes
and doesn't continue.

I close the window manually and when I write - *print (stdout)* - I can get
some output *..ufuk@home-ubuntu:~$ * - as a long string.

But I dont know why it freezes and why I cannot input anything. How should
I continue?


2012/12/21 Prasad, Ramit ramit.pra...@jpmorgan.com

 Ufuk Eskici wrote:
  Hello,
 
  I changed my way. This time I'm using plink under Putty.
 
  My python code is:
 
  os.chdir(c:\\Program Files\\Putty)
  cmd = plink -ssh -l ufuk10.10.10.10 -pw password
  process = subprocess.Popen(cmd)
  inputdata=r van
  result = process.communicate(inputdata)
 
  But after the successful SSH, I cannot continue, no command runs:
  This is the new output after the initial SSH connection:
  No data input.
 
  Last login: Fri Dec 21 16:27:
  ufuk@home-ubuntu:~$

 I am not familiar with plink, so I cannot help you. I recommend using
 an SSH module which help a lot with all of this. That being said, maybe
 this post will help:
 http://code.activestate.com/lists/python-tutor/74807/

 Also take a look at the subprocess.communicate documentation[1] as
 it says
  Interact with process: Send data to stdin. Read data from stdout and
 stderr, until end-of-file is reached. **Wait for process to terminate**.
 The optional input argument should be a string to be sent to the child
 process, or None, if no data should be sent to the child.
 communicate() returns a tuple (stdoutdata, stderrdata).
 Note that if you want to send data to the process's stdin, you need to
 create the Popen object with stdin=PIPE. Similarly, to get anything other
 than None in the result tuple, you need to give stdout=PIPE and/or
 stderr=PIPE too.
  (emphasis added)
 This suggests communicate is waiting for the plink to end? Also, you
 should probably pass in a pipe so that you can send data more than
 once.  Note, I am not familiar with subprocess so YMMV.

 [1]
 http://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate



 Ramit


 This email is confidential and subject to important disclaimers and
 conditions including on offers for the purchase or sale of
 securities, accuracy and completeness of information, viruses,
 confidentiality, legal privilege, and legal entity disclaimers,
 available at http://www.jpmorgan.com/pages/disclosures/email.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-21 Thread eryksun
On Fri, Dec 21, 2012 at 9:44 AM, Ufuk Eskici ufukesk...@gmail.com wrote:

 cmd = plink -ssh -l ufuk10.10.10.10 -pw password
 process = subprocess.Popen(cmd)
 inputdata=r van
 result = process.communicate(inputdata)

 But after the successful SSH, I cannot continue, no command runs:


To use communicate(), you need to set one or more of the standard
streams to a file or pipe (e.g. stdout=subprocess.PIPE). That said, if
you just have a single command, it's simpler to have the ssh client
execute it. Get the result using check_output (it sets up and calls
communicate):

user = 'ufuk'
password = 'password'
host = 10.10.10.10
remote_cmd = 'r van'
cmd = ['plink', '-ssh', '-l', user, '-pw', password, '%s' % remote_cmd]
result = subprocess.check_output(cmd, stdin=subprocess.PIPE)

I had to add stdin=subprocess.PIPE when trying this interactively.
Otherwise plink leaves the console stdin in an unusable state. This is
probably the source of the lockup you're getting.

If you need an interactive, stateful session, then communicate() won't
help since it closes the streams. You'll have to roll your own by
manually handling the stdin/stdout pipes. That means you'll need a
background thread to get around readline blocking (select only works
for sockets on Windows). You'll hit a brick wall with this approach if
the program uses full buffering in a pipe. With Linux you can
sometimes tweak the streams using stdbuf, but not if the program uses
setvbuf(). To get around this in Unix you can use pexpect to fake a
tty. I think that's only available on Windows via Cygwin.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to control putty window

2012-12-20 Thread Ufuk Eskici
Hello,

I run this command and opens putty:

import os
import subprocess
command = 'c:\Program Files\Putty\putty.exe -ssh
ufukeskici@10.10.10.10-pw test
subprocess.Popen(command)

But then I want to input new commands to this Putty new window. How can I
do it?

Thanks.
Ufuk
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-20 Thread David Rock
* Ufuk Eskici ufukesk...@gmail.com [2012-12-20 16:25]:
 Hello,
 
 I run this command and opens putty:
 
 import os
 import subprocess
 command = 'c:\Program Files\Putty\putty.exe -ssh
 ufukeskici@10.10.10.10-pw test
 subprocess.Popen(command)
 
 But then I want to input new commands to this Putty new window. How can I
 do it?

Once you start putty, it is a separate application that python doesn't
really know anything about.  How many commands are you trying to send?
If it's only one or two, you might be able to set up a putty profile
with a couple auto-commands on connect, but that's not the same thing.
If it's a long string of commands, you might be better to pscp a shell
script to the target with one command, and then call that script with
the putty profile.

I would research automating putty first, then see if there are any
options within python to accomplish the same things.

-- 
David Rock
da...@graniteweb.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-20 Thread Dave Angel
On 12/20/2012 09:25 AM, Ufuk Eskici wrote:

 I run this command and opens putty:

 import os
 import subprocess
 command = 'c:\Program Files\Putty\putty.exe -ssh
 ufukeskici@10.10.10.10-pw test
 subprocess.Popen(command)


You really should use cut and paste when trying to tell us what you
tried.  But I'd like to point out that you were just lucky that the file
pathname worked.  You need to use either a raw string, double the
backslashes, or use forward slashes.

-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-20 Thread Alan Gauld

On 20/12/12 14:25, Ufuk Eskici wrote:

Hello,

I run this command and opens putty:

import os
import subprocess
command = 'c:\Program Files\Putty\putty.exe -ssh
ufukeskici@10.10.10.10 mailto:ufukeskici@10.10.10.10 -pw test
subprocess.Popen(command)

But then I want to input new commands to this Putty new window. How can
I do it?



I don't know putty.
But if it reads/writes to stdin/out/error then you can use the options 
to Popen as described in the subprocess docs.


If it doesn't use stdin/out etc then its a much bigger problem.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to control putty window

2012-12-20 Thread Prasad, Ramit
Ufuk Eskici wrote:
 Hello,
 
 I run this command and opens putty:
 
 import os
 import subprocess
 command = 'c:\Program Files\Putty\putty.exe -ssh ufukeskici@10.10.10.10 -pw 
 test
 subprocess.Popen(command)
 
 But then I want to input new commands to this Putty new window. How can I do 
 it?
 

Do you need to control Putty or just SSH to another computer?
If all you need to SSH then I would recommend using a 3rd
party module such as Fabric (which relies on Paramiko). Those modules 
will simply SSH significantly. They are Python 2.x but you should
be able to use Paramiko in 3.x except for SFTP. This link might help
to install Paramiko if you are using Python 3. 
https://github.com/paramiko/paramiko/issues/16

If you need to control Putty specifically then I cannot help.


Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor