Mysql database insert query issue

47 views
Skip to first unread message

SrinivasP EDI Tech Lead

unread,
Nov 6, 2021, 1:08:22 PM11/6/21
to Bots Open Source EDI Translator
Hello There,

Can you please help me with this issue here. 
I am getting below error 
Traceback (most recent call last): File "C:\Python27\lib\site-packages\bots\communication.py", line 1703, in outcommunicate botslib.runscript(self.userscript,self.scriptname,'outcommunicate',channeldict=self.channeldict,dbconnection=self.dbconnection,db_object=db_object) File "C:\Python27\lib\site-packages\bots\botslib.py", line 492, in runscript raise ScriptError(_(u'Userscript "%(modulefile)s": "%(txt)s".'),{'modulefile':modulefile,'txt':txt}) ScriptError: Userscript "C:\Python27\lib\site-packages\bots\usersys\communicationscripts\testmysqldbconnection": "Traceback (most recent call last): File "C:\Python27\lib\site-packages\bots\botslib.py", line 489, in runscript return functiontorun(**argv) File "C:\Python27\lib\site-packages\bots\usersys\communicationscripts\testmysqldbconnection.py", line 17, in outcommunicate cur.execute("""INSERT INTO ccode (ccodeid,leftcode,rightcode) VALUES (%s, %s, $s)""", ( article ) ) File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 159, in execute query = query % db.literal(args) TypeError: not all arguments converted during string formatting

I have attached both communication script and translation script.
Can you please advice me



articlesxml2db.py
testmysqldbconnection.py

A. Gonzalez

unread,
Nov 6, 2021, 2:02:24 PM11/6/21
to Bots Open Source EDI Translator
Hi Srinivas,

i cann't test your plugin but I think Error is on
cur.execute("""INSERT INTO ccode (ccodeid,leftcode,rightcode) VALUES (%s, %s, $s)""", ( article ) )
Have you tried with only one " or with ' ?

BR
Antonio

p srinivas

unread,
Nov 7, 2021, 12:10:23 AM11/7/21
to bots...@googlegroups.com
Hi Antonio,

Thanks for your reply.

I have tried all these options but it doesn't work for me.
Can you please give me any other suggestions if possible.
 

Thanks and Regards

P. Srinivas
EDI Tech Lead



--
You received this message because you are subscribed to a topic in the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/botsmail/TE2XtHnhVig/unsubscribe.
To unsubscribe from this group and all its topics, send an email to botsmail+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/botsmail/1b26d934-1ff1-4d19-8856-4cb1297f13e6n%40googlegroups.com.

p srinivas

unread,
Nov 7, 2021, 1:03:36 AM11/7/21
to bots...@googlegroups.com
Hi

Below code was posted by some user in this group and modified by Henk.


//*********************************************************

import MySQLdb as mdb
import sys
import traceback

def connect(channeldict):
    return mdb.connect('localhost','psvbec','Sairam1979!','test')


def outcommunicate(channeldict, dbconnection,db_object):

    try:
        cursor = dbconnection.cursor()
        for article in db_object:

            cursor.execute(u'''INSERT INTO ccode (ccodeid_id, leftcode, rightcode)
                                VALUES("%(ccodeid)s, %(leftcode)s, %(rightcode)s")''',
                                article)
        connect.commit()
        cursor.close()
    except:
        traceback.print_exc()

 
def disconnect(channeldict, dbconnection):
    dbconnection.close()

//************************************************************************************

But this  code is working but data is not inserted into the database. May I know what could be the problem.


 

Thanks and Regards

P. Srinivas
EDI Tech Lead


p srinivas

unread,
Nov 10, 2021, 12:47:33 AM11/10/21
to bots...@googlegroups.com
  Hello There ,

Thank You  for your support.
Now I am able to fix the MySql database configuration and data insertion issue. 

Thanks

 

Thanks and Regards

P. Srinivas
EDI Tech Lead


Reply all
Reply to author
Forward
0 new messages