MySQL Type Converter Issue - python

I am new to tkinter and I am trying to connect python with MySQL. When I Try to insert the records via a new window in python I get the following error message
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\sapna\anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\sapna\Desktop\SAMARTH.py", line 141, in dynamic_data_entry
libcur.execute("INSERT INTO tcl VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ,
(id1,name1,auth1,doi1,dor1,reiss,rname,Address,gen1,mil1))
File "C:\Users\sapna\anaconda3\lib\site-packages\mysql\connector\cursor_cext.py", line 248, in
execute
prepared = self._cnx.prepare_for_mysql(params)
File "C:\Users\sapna\anaconda3\lib\site-packages\mysql\connector\connection_cext.py", line 626, in
prepare_for_mysql
result = self._cmysql.convert_to_mysql(*params)
_mysql_connector.MySQLInterfaceError: Python type method cannot be converted
Here is the snip of my insert command.
def dynamic_data_entry():
bname.delete(0,END)
bid.delete(0,END)
author.delete(0,END)
DOI.delete(0,END)
DOR.delete(0,END)
RES.delete(0,END)
RNM.delete(0,END)
AD.delete(0,END)
mail.delete(0,END)
id1=ln.get()
name1=fn.get()
auth1=dn.get()
doi1=an.get()
dor1=gn.get()
rname=kn.get()
Address=pn.get
reiss=mn.get()
gen1=var.get()
mil1=ll.get()
libcur.execute("INSERT INTO tcl VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ,
(id1,name1,auth1,doi1,dor1,reiss,rname,Address,gen1,mil1))
mydb.commit()
messagebox.showinfo("INSERT STATUS","RECORD HAS BEEN ADDED SUCCESSFULLY")
libcur.close()
The datatype that I have used is varchar() in Book_id,DOI,DOR and char() in others for MySQL.
All the dataypes that I have used in Python are as follows
var=StringVar()
fn=StringVar()
yn=StringVar()
ln=StringVar()
dn=StringVar()
an=StringVar()
kn=StringVar()
gn=StringVar()
mn=StringVar()
pn=StringVar()
ll=StringVar()
Thanks in advance

Looks like you missed some parentheses in your assignment to Address. Try Address=pn.get().
The error implies that you're passing a method rather than a value. This is consistent with Address=pn.get, i.e. you're passing the pn.get method rather than the return value of pn.get().

Related

[Python]:phoenixdb.errors.ProgrammingError: ("Syntax error. Unexpected char: '!'", 601, '42P00', None)

I am using a python module called phoenixdb to access phoenix which is SQL wrapper to query over HBase.
Here is my code snippet:-
import phoenixdb
database_url = 'http://localhost:8765/'
conn = phoenixdb.connect(database_url, autocommit=True)
cursor = conn.cursor()
cursor.execute("!table")
print cursor.fetchall()
cursor.close()
The phoenix query to list all the schemes and tables is !table or !tables.
But when I try passing the same in the execute function as shown above, I get the following error:-
Traceback (most recent call last):
File "phoenix_hbase.py", line 7, in <module>
cursor.execute("!table")
File "build/bdist.linux-x86_64/egg/phoenixdb/cursor.py", line 242, in execute
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 345, in prepareAndExecute
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 184, in _apply
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 90, in parse_error_page
phoenixdb.errors.ProgrammingError: ("Syntax error. Unexpected char: '!'", 601, '42P00', None)
Funny part is when I try to passing a different query, for example a select query, then script gets executed and produces result just fine.
Query:cursor.execute("select * from CARETESTING.EDR_BIN_SOURCE_3600_EDR_FLOW_SUBS_TOTAL limit 1")
Result:
[[2045,1023,4567]]
Is there any other format for passing !table which is equivalent to show tables in phoenixdb library's execute function which I am missing?
I tried looking up on the internet but unfortunately haven't come across anything helpful so far.
Thanks
!tables is sqlline grammar that can not be parsed by JDBC interface.

xlwings call from Excel VBA function produces error

The call from EXCEL sub to python using xlwings works fine but wen triggering this same VBA via a VBA function the following error is generated:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\a112833\google drive\mytechtests\pulp\mymodule.py", line 13, in energySystemSimulator
wb = Workbook.caller()
File "C:\Python27\lib\site-packages\xlwings\main.py", line 233, in caller
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=sys.argv[4])
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 142, in get_open_workbook
duplicate_fullnames = get_duplicate_fullnames()
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 124, in get_duplicate_fullnames
for xl_app in get_xl_apps():
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 96, in get_xl_apps
xl_app = get_xl_app_from_hwnd(hwnd)
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 73, in get_xl_app_from_hwnd
return disp.Application
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.Application
This works:
Sub eSS()
RunPython ("import mymodule; mymodule.eSS()")
End Sub
This breaks with the traceback above (ignore fn. arguments):
Function fnESS(x As Double, y As Double) As Double
Call eSS
fnESS = ActiveWorkbook.Sheets("Config").Range("T10")
End Function
I checked call signature seems exactly the same using VBA sub or function sub call. I can't see what is causing the error.
You're seeing a common trap when writing User Defined Functions: Excel only allows you to write to the calling cells, not outside of it. That's a limitation by Excel, really.
xlwings might offer a workaround for this one day, but right now, there's no official support for this.
As a side note: you might actually be better off writing UDFs by using the xlwings decorators (at least if you are using Windows only), see here.

python and elastic search update errors

today I'm updated the elastic search from 1.6 to 2.1, because 1.6 is vulnerable version, after this update my website not working, give this error :
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from app import app, db
File "/opt/project/app/__init__.py", line 30, in <module>
es.create_index(app.config['ELASTICSEARCH_INDEX'])
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 93, in decorate
return func(*args, query_params=query_params, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 1033, in create_index
query_params=query_params)
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 285, in send_request
self._raise_exception(status, error_message)
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 299, in _raise_exception
raise error_class(status, error_message)
pyelasticsearch.exceptions.ElasticHttpError: (400, u'index_already_exists_exception')
make: *** [run] Error 1
the code is this :
redis = Redis()
es = ElasticSearch(app.config['ELASTICSEARCH_URI'])
try:
es.create_index(app.config['ELASTICSEARCH_INDEX'])
except IndexAlreadyExistsError, e:
pass
where is wrong ? what is new on this new version ?
You're getting the following error: index_already_exists_exception
This means that you're trying to create an index that already exists. The second time you run your program you either need to delete your index first or create it only if it doesn't exist.
You have handled the exception using IndexAlreadyExistsError. Try using TransportError to handle the exception.
And you can also add a check like :
exist = es.indices.exists(index_name)
if not exist:
es.create_index(app.config['ELASTICSEARCH_INDEX'])

I'm getting an error from grid.after_idle() in tkinter

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1456, in __call__
return self.func(*args)
File "C:\Users\littl_000\Documents\Python\pd\PD GUI.py", line 185, in playmove
grid.after_idle(automove(""))
File "C:\Python32\lib\tkinter\__init__.py", line 534, in after_idle
return self.after('idle', func, *args)
File "C:\Python32\lib\tkinter\__init__.py", line 516, in after
self.tk.call('after', ms)
_tkinter.TclError: wrong # args: should be "after idle script script ..."
The code is just, grid.after_idle(automove(""))
It worked before but it was spaghetti code where I called a function within another function, the automove moves some dots on a grid ( lots of dots very quickly, its a maths problem) and I'm using the after idle so that the tkinter window doesn't crash when I try to move it even when this loop is running, it can take minutes. I have no idea what this error means however, and it doesnt seem to work when i use main.update_idletasks()
after_idle takes a reference to a function. When you do this:
grid.after_idle(automove(""))
... you are immediately calling automove, and the result of that function is what is getting passed to after_idle. The above is exactly the same as:
result = automove("")
grid.after_idle(result)
Most likely automove("") is returning None, which is why after_idle is throwing the error that it is throwing.
If you need to pass arguments, you can include them as additional arguments to after_idle:
grid.after_idle(automove, "")

Syntax for changing a python script from sqlite3 to mysql

I have a working python script which retrieves data from a sqlite3 db. I need to convert it to talk to a mysql db though, and here's the first line that is giving me grief:
PRODUCT_CODE_ID = "SELECT id FROM localsite_productcode WHERE localsite_productcode.product_code=?"
cur.execute(PRODUCT_CODE_ID,(product_code,))
When I try that with mysql I get the following error:
Traceback (most recent call last):
File "gen-csv.py", line 85, in <module>
cur.execute(PRODUCT_CODE_ID,(product_code,))
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 151, in execute
query = query % db.literal(args)
TypeError: not all arguments converted during string formatting
What am I doing wrong here?
I don't think the DB API for MySQL supports the ? as a place holder - just try %s instead.

Categories