Advertisement
Guest User

Untitled

a guest
Feb 12th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. mysql.connector.errors.ProgrammingError: Failed processing format-parameters;
  2. Python 'ndarray' cannot be converted to a MySQL type
  3.  
  4. import sys
  5. import collections
  6. import os
  7. import netCDF4
  8. import calendar
  9. from netCDF4 import Dataset
  10. import mysql.connector
  11. from mysql.connector import errorcode
  12.  
  13. table = 'rob-tabl'
  14. con = mysql.connector.connect(user='rob', password='xxxx',
  15. database=roby)
  16. cursor = con.cursor()
  17.  
  18. smeData = "INSERT INTO `" + table + "` "
  19. .
  20. .
  21. .
  22. .
  23. .Here I define MYSQL columns
  24. .
  25. .
  26. .
  27.  
  28. data_array = []
  29. for item in totfiles.items(): # loop on different netCDF files in a directory , but at the moment I had only one file
  30. nc = Dataset('filename', 'r')
  31. data1 = nc.variables['time'][:]
  32. data2 = nc.variables['microsec'][:]
  33. data3 = nc.variables['temperature'][:]
  34. data4 = nc.variables['humidity'][:]
  35. data5 = nc.variables['pressure'][:]
  36. data = data1 + data2 + data3 + data4 + data5
  37. data_array.append(data)
  38. print 'data_array: ', data_array
  39. cursor.execute(smeData, data_array)
  40.  
  41. data_array = []
  42. for item in totfiles.items():
  43. nc = Dataset('filename', 'r')
  44. data1 = nc.variables['time'][:]
  45. data_array.append(data)
  46. print 'data_array: ', data_array
  47. cursor.execute(smeData, data_array)
  48.  
  49. "One of your passed values could be of type numpy.float64 which is not recognized
  50. by the MySQL connector. Cast it to a genuine python float on populating the dict."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement