Failed processing format-parameters; Python 'maskedarray' cannot be converted to a MySQL type

65 Views Asked by At

I'm still new to python linked to MySQL, and I'm getting a problem like below. are there any clues I should do? Here is my code:

import mysql.connector 
from netCDF4 import Dataset 
import numpy as np 
import matplotlib.pyplot as plt 
import cartopy.crs as ccrs 
import pyodbc
 
file = '182.16.248.173:8080/dods/INA-NWP/2021030100/2021030100-d02-asim' 
url = Dataset(file) rainc = url.variables['rainc'][7,0,:,:] 

con = mysql.connector.connect( host = "", user = "", password = "", db = "" ) 

dbcursor = con.cursor() 

sql = "INSERT INTO gis (id, name, var1) VALUES (%s, %s, %s)"
data = ("01", "2021030100", rainc) 
dbcursor.execute(sql, data) 
con.commit()
 
print("records inserted") 
1

There are 1 best solutions below

2
On

MySQL doesn't accept arrays at all masked or otherwise. The error is simply reading back to you the data type you are sending, in this case a maskedarray in the form of rainc, and telling you that there is no equivalent MySQL data type, or that where you are sending it doesn't accept that data type.

This documentation about MySQL data types should clear it up:

https://dev.mysql.com/doc/refman/8.0/en/data-types.html