Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. Traceback (most recent call last):
  2. File "interbasecom.py", line 271, in <module>
  3. classPresupuesto.getPresupuestos()
  4. File "interbasecom.py", line 268, in getPresupuestos
  5. json.dump(rowarray_list_two, fileInetrbase, cls=DecimalEncoder,default=date_handler, ensure_ascii = False)
  6. File "C:Python27libjson__init__.py", line 181, in dump
  7. for chunk in iterable:
  8. File "C:Python27libsite-packagessimplejsonencoder.py", line 665, in _iterencode
  9. for chunk in _iterencode_list(o, _current_indent_level):
  10. File "C:Python27libsite-packagessimplejsonencoder.py", line 515, in _iterencode_list
  11. for chunk in chunks:
  12. File "C:Python27libsite-packagessimplejsonencoder.py", line 602, in _iterencode_dict
  13. yield _encoder(value)
  14. File "C:Python27libsite-packagessimplejsonencoder.py", line 61, in encode_basestring
  15. s = s.decode('utf-8')
  16. File "C:Python27libencodingsutf_8.py", line 16, in decode
  17. return codecs.utf_8_decode(input, errors, True)
  18. UnicodeDecodeError: 'utf8' codec can't decode byte 0xba in position 7: invalid start byte
  19.  
  20. #!/usr/bin/env python
  21. # -*- coding: utf-8 -*-
  22. import wx
  23. import kinterbasdb
  24. import os
  25. import sys
  26. import MySQLdb
  27. import datetime
  28. import time
  29. from os.path import exists
  30. import time
  31. from threading import Timer
  32. import shutil
  33. import string
  34. from connections import *
  35. import json
  36. from decimal import *
  37. from pprint import pprint
  38. import decimal, simplejson
  39.  
  40.  
  41. def date_handler(obj):
  42. if hasattr(obj, 'isoformat'):
  43. return obj.isoformat()
  44. else:
  45. raise TypeError
  46.  
  47.  
  48.  
  49. class DecimalEncoder(simplejson.JSONEncoder):
  50. def default(self, o):
  51. if isinstance(o, decimal.Decimal):
  52. return str(o)
  53. return super(DecimalEncoder, self).default(o)
  54.  
  55.  
  56.  
  57.  
  58. class InterbaseCom(DecimalEncoder):
  59.  
  60. def decimal_default(obj):
  61. if isinstance(obj, decimal.Decimal):
  62. return float(obj)
  63. else:
  64.  
  65. raise TypeError
  66.  
  67.  
  68.  
  69. def getPresupuestos(self):
  70.  
  71. connectionsCls = Connections()
  72. #conexion con firebird
  73. conGDB = connectionsCls.interbase
  74. #conexion con mysql
  75. conMysql = connectionsCls.dbMysql
  76.  
  77.  
  78. rowarray_list = []
  79.  
  80. sqlSelect_account = """ Call SELECT_ACCOUNT()"""
  81. cursorSelect_account= conMysql.cursor()
  82. cursorSelect_account.execute(sqlSelect_account)
  83. for cuenta in cursorSelect_account:
  84. clienteId = cuenta[0]
  85. descripcionId=cuenta[1]
  86.  
  87. clientes ={
  88. "Cuentas":{
  89. "ClientID":clienteId,
  90. "ClientDescri":descripcionId
  91. }}
  92.  
  93.  
  94.  
  95.  
  96.  
  97. rowarray_list.append(clientes)
  98. with open('cuentasMysql.json', 'w') as file:
  99. json.dump(rowarray_list, file, encoding='latin1')
  100.  
  101. #leer = json.loads(open('cuentasMysql.json').read())
  102.  
  103.  
  104. with open('cuentasMysql.json') as data_file:
  105.  
  106. data = json.load(data_file)
  107. for fileread in data:
  108.  
  109. #pprint(fileread['Cuentas']['ClientID'])
  110.  
  111. sqlVecomproPresu = """SELECT
  112. *
  113. FROM
  114. EMPRESAFST(null,null, null,
  115. null, null, null, null, null,
  116. null, null,null,null,null,
  117. null, null, null, '%s', '%s',
  118. null, null, null,null, null,
  119. null,null, null,null,
  120. null, '1', null,null,null,
  121. null,null)"""%(fileread['Cuentas']['ClientID'],fileread['Cuentas']['ClientID'])
  122.  
  123. cursorSelect_Interbase= conGDB.cursor()
  124. cursorSelect_Interbase.execute(sqlVecomproPresu)
  125.  
  126. for cuentasInetrbase in cursorSelect_Interbase:
  127. rowarray_list_two=[]
  128. vecompropresuInterbase=[]
  129. vecompropresuInterbase = {
  130. "CLIENTE":cuentasInetrbase[0],
  131. "CLI": cuentasInetrbase[1],
  132. "DE": cuentasInetrbase[2],
  133. "AG": cuentasInetrbase[3],
  134. "DES":cuentasInetrbase[4],
  135.  
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. rowarray_list_two.append(vecompropresuInterbase)
  144. with open('cuentasInterbase.json','w') as fileInetrbase:
  145. json.dump(rowarray_list_two, fileInetrbase, cls=DecimalEncoder,default=date_handler, ensure_ascii = False)
  146. t0 = time.clock()
  147. classPresupuesto = InterbaseCom()
  148. classPresupuesto.getPresupuestos()
  149. print "%.2f sec" % (time.clock() - t0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement