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


Groups > comp.lang.python > #59946

Re: Cannot connect to Mysql database

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'duplicate': 0.07; 'error:': 0.07; 'importerror:': 0.07; 'skip:/ 10': 0.09; 'try:': 0.09; '"file': 0.16; 'execute,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garg': 0.16; 'helps.': 0.16; 'sys.modules': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; 'written': 0.21; 'import': 0.22; 'print': 0.22; 'directory.': 0.24; 'looks': 0.24; 'script': 0.25; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'checked': 0.32; 'skip:m 30': 0.32; 'run': 0.32; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'skip:" 50': 0.36; 'doing': 0.36; 'skip:o 20': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'manually': 0.60; 'full': 0.61; "you're": 0.61; 'more': 0.64; 'as:': 0.81; 'system),': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=7nt65bh77qeFMJE7oD6zgu+CqQR2+TFV5pwOB83ydUI=; b=lP//x3OJBFE/+mntEjAHVp5JZK/OVknsWle/CnjSP5i8Q0fQVsKDtvByfsmzholfgE Ik1eWypW94yP7XH0N9bhN54uS/NXxP8v7ZPPfh5aoLiuN0De7dF4p7mCfXFeDCY3iklH NwPvaCGB+0iqoT0fEoZ2db6Vxf+w+UwWBy6uHHxCo6JbrQcTM3A/ulVKc1JS+HW2e6y6 QoQMj5g8rKzxziYXXvQfWxqWmL5CUfWooWJDArnKKUhvd2rUPYhXL+tg6UDRo4eSzLa9 wsOJMJlpusAG4npkGqTamS86c+/7AW27WN0S2A+GE+Sv4HiUBLm1G/7G7vX3Ua8y/MRS TS0g==
MIME-Version 1.0
X-Received by 10.68.230.228 with SMTP id tb4mr17263844pbc.108.1384841404753; Mon, 18 Nov 2013 22:10:04 -0800 (PST)
In-Reply-To <77a212a3-d33c-4df0-a73d-eb1753e17227@googlegroups.com>
References <77a212a3-d33c-4df0-a73d-eb1753e17227@googlegroups.com>
Date Tue, 19 Nov 2013 17:10:04 +1100
Subject Re: Cannot connect to Mysql database
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2883.1384841408.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384841408 news.xs4all.nl 15942 [2001:888:2000:d::a6]:40488
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59946

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web