PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] Connecting to MySQL with Python in Ubuntu (Weird Error)

 January 13, 2022     lamp, mysql, mysql-python, python, ubuntu     No comments   

Issue

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.


Solution

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.



Answered By - Ned Deily
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,217,358

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing