Re: [Tutor] connect to a remote machine - Linux

2006-06-12 Thread Patricia G.
Thank you for the great explanation, Danny.. I was confused...
Thank you all for your help!

PatriciaOn 6/11/06, Danny Yoo [EMAIL PROTECTED] 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..Hi Patricia,There's some confusion here.Let's get that out in the open.
It sounds like you have a remote server.That server provides login shellservice through ssh, and this login shell service runs on port 22, Ithink.But if your server is running MySQL, it is very likely that it
provides network access to that MySQL database through port 3306.I think you believe that ssh login access is required to access MySQL onyour remote network server.But this is not necessarily true: one can
access MySQL remotely without having a login shell account into themachine.That is, rather than: Client  Login through SSH  Execute mysql clientwhich is three steps, the conventional route here is:
 Client  Connect to networked MySQL using a database driver(MySQLdb)which is more direct.See: MySQLdb: 
http://sourceforge.net/projects/mysql-pythonas well as: http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/
However, this does mean that the remote MySQL server has to be set up witha separate MySQL username/password account.That is, MySQL keeps its ownset of usernames and passwords that can be separate from the shell
logins.Also, mysqld --- the software that drives the MySQL server --- has to beenabled to work across tcp.That requirement sounds obvious enough, butit is not the default in the MySQL server installs I've seen lately, so
double check this with your database system administrator.In short: youcan not automatically assume that having login access to the machine willgive you MySQL database access, and visa-versa.Does this make sense so far?
 I read somewhere that os.popen would work, but I'm not sure if that will do for meAlmost certainly no.popen is not for external database access.People have written databasedrivers to solve this problem for you already.It is perhaps possible to
bend popen() in such a way to access MySQL, but this will involve anamount of work to get right, and there will be a lot of ways of getting itwrong.*grin*So I'd recommend changing this question from: How do I get popen() to
access MySQL across a remote interface? to a more general: How do Iconnect to MySQL from Python?The link above to MySQLdb will give youthe software necessary to connect your client to a MySQL server, and the
link to the Devshed article is a tutorial on how to use it effectively.Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Michael Sullivan
On Sun, 2006-06-11 at 15:19 +, 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'd appreciate any help.
 Thanks!!
 
 Patricia




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Python
On Sun, 2006-06-11 at 15:19 +, 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@python.org
 http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Roy Mac
Try looking at PyDO - This provides an interface between Python and your
database.  This allows you to change your database at a later time and not
have to change any Python.

The excerpt below is from:
http://skunkweb.sourceforge.net/PyDO2/api/html/public/pydo-module.html

PyDO (Python Data Objects) is an object-relational wrapper for
relational databases.  It provides a convenient API for retrieving and
manipulating data without constraining in any way how the data is
persisted at the RDBMS level.  Supported databases are:

   * postgresql
   * mysql
   * sqlite
   * mssql
   * oracle 



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Patricia
Sent: Sunday, June 11, 2006 4:19 PM
To: tutor@python.org
Subject: [Tutor] connect to a remote machine - Linux

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'd appreciate any help.
Thanks!!

Patricia

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Patricia G.

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..I read somewhere that os.popen would work, but I'm not sure if that willdo for me because I have to enter a passphrase and password to connect to the remote machine. 

Any ideas??

Thanks,

Patricia
On 6/11/06, Roy Mac [EMAIL PROTECTED] wrote:
Try looking at PyDO - This provides an interface between Python and yourdatabase.This allows you to change your database at a later time and not
have to change any Python.The excerpt below is from:http://skunkweb.sourceforge.net/PyDO2/api/html/public/pydo-module.html
PyDO (Python Data Objects) is an object-relational wrapper forrelational databases.It provides a convenient API for retrieving andmanipulating data without constraining in any way how the data ispersisted at the RDBMS level.Supported databases are:
* postgresql* mysql* sqlite* mssql* oracle-Original Message-From: [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED]] On BehalfOf PatriciaSent: Sunday, June 11, 2006 4:19 PMTo: tutor@python.orgSubject: [Tutor] connect to a remote machine - LinuxHi All,
I need to connect to a remote computer on the same network to store datainto 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 andpassword to successfully connect to it..I'd appreciate any help.Thanks!!Patricia___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Python
(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 [EMAIL PROTECTED] wrote: 
 On Sun, 2006-06-11 at 15:19 +, 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@python.org
  http://mail.python.org/mailman/listinfo/tutor
 --
 Lloyd Kvam
 Venix Corp
 
 
-- 
Lloyd Kvam
Venix Corp

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Danny Yoo


 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..

Hi Patricia,

There's some confusion here.  Let's get that out in the open.

It sounds like you have a remote server.  That server provides login shell 
service through ssh, and this login shell service runs on port 22, I 
think.  But if your server is running MySQL, it is very likely that it 
provides network access to that MySQL database through port 3306.

I think you believe that ssh login access is required to access MySQL on 
your remote network server.  But this is not necessarily true: one can 
access MySQL remotely without having a login shell account into the 
machine.  That is, rather than:

 Client  Login through SSH  Execute mysql client

which is three steps, the conventional route here is:

 Client  Connect to networked MySQL using a database driver
  (MySQLdb)

which is more direct.


See:

 MySQLdb: http://sourceforge.net/projects/mysql-python

as well as:

 http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/


However, this does mean that the remote MySQL server has to be set up with 
a separate MySQL username/password account.  That is, MySQL keeps its own 
set of usernames and passwords that can be separate from the shell 
logins.

Also, mysqld --- the software that drives the MySQL server --- has to be 
enabled to work across tcp.  That requirement sounds obvious enough, but 
it is not the default in the MySQL server installs I've seen lately, so 
double check this with your database system administrator.  In short: you 
can not automatically assume that having login access to the machine will 
give you MySQL database access, and visa-versa.

Does this make sense so far?


 I read somewhere that os.popen would work, but I'm not sure if that will 
 do for me

Almost certainly no.

popen is not for external database access.  People have written database 
drivers to solve this problem for you already.  It is perhaps possible to 
bend popen() in such a way to access MySQL, but this will involve an 
amount of work to get right, and there will be a lot of ways of getting it 
wrong.  *grin*


So I'd recommend changing this question from: How do I get popen() to 
access MySQL across a remote interface? to a more general: How do I 
connect to MySQL from Python?  The link above to MySQLdb will give you 
the software necessary to connect your client to a MySQL server, and the 
link to the Devshed article is a tutorial on how to use it effectively.


Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor