Python MySQL error


 
Thread Tools Search this Thread
Top Forums Programming Python MySQL error
# 1  
Old 06-27-2011
Python MySQL error

Hey all,
I'm trying to enter some data into a database and I keep getting this error:
Code:
Traceback (most recent call last):
  File "./ais_file_parser.py", line 77, in <module>
    cursor.execute(sql)
  File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near '('366978440', '46.500150', '-84.338107', CURRENT_TIMESTAMP)' at line 3")

The mysql command that I'm running is this:
Code:
#add the location entry to the database
sql = "INSERT INTO `ship_location`\n \
VALUES (`userid`, `latitude`, `longitude`, `date_time`) \n \
('%d', '%f', '%f', CURRENT_TIMESTAMP);" % (msg.userid, DMToDec(lat_dd, lat_min), DMToDec(long_ddd, long_min))

I set up the database so the date_time field has a default of the CURRENT_TIMESTAMP. From the error message, you can see that the userid is being sent an integer, and the latitude and longitude are both getting floats and when I set up their fields in MySQL I set them as FLOAT(10,6). So it might then be a problem with the sql syntax, but I can't see it. I've tried tried multiple ways of doing it, so I'm kind of at my wits end with it.

Any help would be appreciated.

[edit] Also thought I should add that I tried entering 366978440, 46.500150, -84.338107 into the user_id, longitude and latitude fields respectfully, and it works.

Last edited by pmd006; 06-27-2011 at 12:22 PM..
# 2  
Old 06-28-2011
Figured out my problem, I had "VALUES" in the wrong place. Needed to go after the names of the columns.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Tuple Error in Python

Hi, I am getting the below error: AttributeError: 'tuple' object has no attribute 'field_id' This line is complaining on the below code snippet: field_list = for f in source_rows: field_list.append(f.field_id) Where source_rows returns multiple rows of... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

2. Red Hat

Error ERROR 1045 (28000) in the MYSQL

im install mysql inthe centos 6.7 now but when set password received error chkconfig mysqld on # service mysqld start Starting mysqld: mysqladmin -u root password mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user... (0 Replies)
Discussion started by: mnnn
0 Replies

3. Shell Programming and Scripting

Python Name Error

Hi There, I have the following code: import time import paramiko node_list = for node in node_list: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(node, username='lord', password='xxxx') variables = {} stdin,... (3 Replies)
Discussion started by: infinitydon
3 Replies

4. Shell Programming and Scripting

python - string encoding error

I'm trying to pull a google calendar (successful) and then put the contents into a mysql db (almost successful). On one of the field I keep getting an encode error: #!/usr/bin/python from xml.etree import ElementTree import gdata.calendar.data import gdata.calendar.client import... (12 Replies)
Discussion started by: unclecameron
12 Replies

5. Shell Programming and Scripting

python script error

Hi I have written a script in python and used it inside Ubuntu and its worked for me. The script import email.utils, however in centos when I try to run the script I get: Traceback (most recent call last): File "./warning.py", line 4, in ? import email.utils ImportError: No... (2 Replies)
Discussion started by: programAngel
2 Replies

6. Solaris

Error in installing the mysql-python-1.2.3.tar.gz

Hi, I followed the step written in README. It got some error message when I type " #python setup.py build" running build running build_py copying MySQLdb/release.py -> build/lib.solaris-2.11-i86pc-2.4/MySQLdb running build_ext building '_mysql' extension /usr/lib/python2.4/pycc -DNDEBUG... (2 Replies)
Discussion started by: AlexCheung
2 Replies

7. Programming

Error in Python Embeded in Qt C++

hi i have an error in script language when run it i use python 2.4, CentOS 5.5, Qt C++ 2010/04 the error is SystemError: null argument to internal routine the Python Code def main(i): print i if __name__ == "__main__": main(i) the C++ Code PyObject *objModule =... (0 Replies)
Discussion started by: HanyM.Magdy
0 Replies

8. UNIX and Linux Applications

mysql syntax error ?

hi, I receive this error when I export/import a table from a database to another one: Error SQL query: -- -- Database: `mil` -- -- -------------------------------------------------------- -- -- Table structure for table `jos_taoj` -- CREATE TABLE IF NOT EXISTS `jos_taoj` ( ... (2 Replies)
Discussion started by: aneuryzma
2 Replies

9. Linux

MySQL python installation

Hi I am using CentOS 4 machine..trying to install MySQL for python to setup a boinc project.. During the building process I am getting this error..I have even set the LD_lIBRARY_PATH to /usr/local/lib where the libmysqlclient.so file is present.. ./python -E ./setup.py build ./python: error... (1 Reply)
Discussion started by: Gayathrirri
1 Replies
Login or Register to Ask a Question