Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59945 > unrolled thread

Cannot connect to Mysql database

Started byHimanshu Garg <hgarg.india@gmail.com>
First post2013-11-18 22:03 -0800
Last post2013-11-19 17:31 +1100
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Cannot connect to Mysql database Himanshu Garg <hgarg.india@gmail.com> - 2013-11-18 22:03 -0800
    Re: Cannot connect to Mysql database Chris Angelico <rosuav@gmail.com> - 2013-11-19 17:10 +1100
    Re: Cannot connect to Mysql database Chris Angelico <rosuav@gmail.com> - 2013-11-19 17:13 +1100
    Re: Cannot connect to Mysql database Himanshu Garg <hgarg.india@gmail.com> - 2013-11-18 22:26 -0800
      Re: Cannot connect to Mysql database Chris Angelico <rosuav@gmail.com> - 2013-11-19 17:31 +1100

#59945 — Cannot connect to Mysql database

FromHimanshu Garg <hgarg.india@gmail.com>
Date2013-11-18 22:03 -0800
SubjectCannot connect to Mysql database
Message-ID<77a212a3-d33c-4df0-a73d-eb1753e17227@googlegroups.com>
I have written the script as:

import os
import MySQLdb as mdb

os.chroot("/lxc/rootfs")
os.chdir("/")
con = mdb.connect(host="192.168.1.7", user="root", passwd="password")
print "opened"
con.close()

But when I execute, I get the following error:

"File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 80, in Connect
ImportError: No module named connections"

I have checked there is a connections.py module in the above directory.  Also, when I run the script without doing chroot, it works perfectly.

[toc] | [next] | [standalone]


#59946

FromChris Angelico <rosuav@gmail.com>
Date2013-11-19 17:10 +1100
Message-ID<mailman.2883.1384841408.18130.python-list@python.org>
In reply to#59945
On Tue, Nov 19, 2013 at 5:03 PM, Himanshu Garg <hgarg.india@gmail.com> wrote:
> I have written the script as:
>
> import os
> import MySQLdb as mdb
>
> os.chroot("/lxc/rootfs")
> os.chdir("/")
> con = mdb.connect(host="192.168.1.7", user="root", passwd="password")
> print "opened"
> con.close()
>
> But when I execute, I get the following error:
>
> "File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 80, in Connect
> ImportError: No module named connections"
>
> I have checked there is a connections.py module in the above directory.  Also, when I run the script without doing chroot, it works perfectly.

Do you have a full duplicate of your /usr/lib/python2.7 inside
/lxc/rootfs? It looks like the connect call is trying to import
something, and now that you're chrooted, it can't find it. The
solution might be to manually import a few more modules beforehand
(putting them into sys.modules means they don't need to come from the
file system), or to add more files to your chroot jail.

For a guess, I would try:

import MySQLdb.connections

above your chroot, and see if that helps.

ChrisA

[toc] | [prev] | [next] | [standalone]


#59948

FromChris Angelico <rosuav@gmail.com>
Date2013-11-19 17:13 +1100
Message-ID<mailman.2884.1384841590.18130.python-list@python.org>
In reply to#59945
On Tue, Nov 19, 2013 at 5:10 PM, Chris Angelico <rosuav@gmail.com> wrote:
> For a guess, I would try:
>
> import MySQLdb.connections
>
> above your chroot, and see if that helps.

And possibly also converters, cursors, release, times, and maybe
constants. I just peeked at the MySQLdb source code to see what's in
the package.

ChrisA

[toc] | [prev] | [next] | [standalone]


#59951

FromHimanshu Garg <hgarg.india@gmail.com>
Date2013-11-18 22:26 -0800
Message-ID<877f2a4a-5919-456a-8fa3-eb4b12ae8918@googlegroups.com>
In reply to#59945
I did:

import MySQLdb as mdb
from MySQLdb import *
from MySQLdb.constants import *

and now it works.  Thanks! again

[toc] | [prev] | [next] | [standalone]


#59952

FromChris Angelico <rosuav@gmail.com>
Date2013-11-19 17:31 +1100
Message-ID<mailman.2885.1384842695.18130.python-list@python.org>
In reply to#59951
On Tue, Nov 19, 2013 at 5:26 PM, Himanshu Garg <hgarg.india@gmail.com> wrote:
> I did:
>
> import MySQLdb as mdb
> from MySQLdb import *
> from MySQLdb.constants import *
>
> and now it works.  Thanks! again

Looks good! Glad it works.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web