[Tutor] connect to a remote machine - Linux

Python python at venix.com
Mon Jun 12 02:28:13 CEST 2006


(back on list)
On Sun, 2006-06-11 at 18:59 -0400, Patricia G. wrote:
> I'm sorry. I think I didn't explain myself well. My problem is not
> with the database.. The part I'm not sure how to do is connect to the
> remote computer.. 
MySQL will accept connections from other computers.  It listens on port
3306.  There are network setup and security issues, but those would be
outside the scope of a Python database program.

> I read somewhere that os.popen would work, but I'm not sure if that
> will do for me because I have to enter a passphrase and password to
> connect to the remote machine.
I presume that was using os.popen to talk to stdin/stdout files
connected to a telnet or ssh session established from outside Python.
That is likely to prove pretty clumsy for all but the simplest cases.

> Any ideas??
Logging on to a remote computer should not have anything to do with
accessing a remote MySQL database.

ssh would probably be the preferred way to login to a remote computer.
http://www.lag.net/paramiko/
would appear to do the trick.

If you're stuck with telnet, the stdlib has a telnetlib module that
would help.

http://pexpect.sourceforge.net/
Provides an expect like module to help manage a terminal session
conversation.

In general, program-to-program interaction between computers works best
with protocols that were designed for programs.  Telnet expects a person
who will interpret error strings, not type too quickly, and understand
(and wait for) prompts.

Obviously, I don't know your situation, but scripting remote terminal
sessions should be a last resort.  (I used to do it a lot (15 - 20 years
ago) over serial connections where there was no alternative protocol.)

>  
> Thanks,
> Patricia  
> 
>  
> On 6/11/06, Python <python at venix.com> wrote: 
>         On Sun, 2006-06-11 at 15:19 +0000, Patricia wrote:
>         > Hi All,
>         >
>         > I need to connect to a remote computer on the same network
>         to store data into 
>         > its mysql database, and I need to do this using python
>         script.
>         >
>         > Although I've used mysql and python before, I have no idea
>         how to access a
>         > remote computer with Python. Also, I would have to enter a
>         passphrase and 
>         > password to successfully connect to it..
>         
>         I could not simply cut and paste working code, but this should
>         get you
>         started.  There is no programming difference in using a remote
>         sql
>         server.
>         
>         import MySQLdb 
>         
>         dbparms = {
>            'host':'dbserver.example.com',  # name of sql server
>                                            # (localhost for your local
>         computer)
>            'user':'dbusername',        # your identifier 
>            'passwd':'dbpassword',      # your password
>            'db':'dbname_to_use',       # initial database
>            }
>         conn = MySQLdb.connect( **dbparms)
>         
>         
>         >
>         > I'd appreciate any help.
>         > Thanks!!
>         > 
>         > Patricia
>         >
>         > _______________________________________________
>         > Tutor maillist  -  Tutor at python.org
>         > http://mail.python.org/mailman/listinfo/tutor
>         --
>         Lloyd Kvam
>         Venix Corp
>         
> 
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list