rabunc
rabunc

Reputation: 67

Connecting to MySQL with Python in Ubuntu (Weird Error)

I'm using ubuntu 10.10, and after making the mistake of installing LAMP, (was unable to connect to a database with it), I came here and read how important it is to use apt-get install python-mysqldb instead. Deleted LAMP, re-installed using apt-get, and am now getting the same error when trying to run a basic server_version.py script.

The script is the server_version.py found here: http://www.kitebird.com/articles/pydbapi.html

My server_version.py script:

# server_version.py - retrieve and display database server version

import MySQLdb

# I have also tried setting host = 'localhost'
conn = MySQLdb.connect (host = "/opt/lampp/var/mysql/mysql.sock",
                user = "root",
                passwd = "myrealpass",
                db = "testdb1")


cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close ()
conn.close ()

The error is:

Traceback (most recent call last): File "server_version.py", line 10, in db = "testdb1")

File "/usr/lib/pymodules/python2.6/MySQLdb/init.py", line 81, in Connect return Connection(*args, **kwargs)

File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 129, in init from converters import conversions

File "/usr/lib/pymodules/python2.6/MySQLdb/converters.py", line 165, in from decimal import Decimal

File "/usr/lib/python2.6/decimal.py", line 137, in import copy as _copy

File "/home/browning/copy.py", line 4, in

ValueError: need more than 1 value to unpack

Just trying to get some basic experience using databases with python here, so I'm not set on MySQL if there is a better option. I have attempted to re-install mysqldb multiple times using apt-get and pip.

Upvotes: 0

Views: 434

Answers (1)

Ned Deily
Ned Deily

Reputation: 85045

It looks like you have a file named copy.py that is being picked up instead of the Python standard library module copy. Rename or delete your file (and copy.pyc if it was created). Or run from a different directory.

Upvotes: 3

Related Questions