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

Search Discussions

  • Chris Angelico at Nov 19, 2013 at 6:10 am

    On Tue, Nov 19, 2013 at 5:03 PM, Himanshu Garg 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
  • Chris Angelico at Nov 19, 2013 at 6:13 am

    On Tue, Nov 19, 2013 at 5:10 PM, Chris Angelico 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
  • Himanshu Garg at Nov 19, 2013 at 6:26 am
    I did:


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


    and now it works. Thanks! again
  • Chris Angelico at Nov 19, 2013 at 6:31 am

    On Tue, Nov 19, 2013 at 5:26 PM, Himanshu Garg 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 19, '13 at 6:03a
activeNov 19, '13 at 6:31a
posts5
users2
websitepython.org

2 users in discussion

Chris Angelico: 3 posts Himanshu Garg: 2 posts

People

Translate

site design / logo © 2022 Grokbase