ASCII read issue when compiled with py2exe
Created originally on Bitbucket by Anonymous
Hello,
When I compiled my python program I get this error (python vs. 2.7 latest vs of openpyxl 1.5.0)
The Error:
Exception in Tkinter callback Traceback (most recent call last): File "Tkinter.pyc", line 1410, in call File "combined.py", line 28, in File "combined.py", line 141, in loadDefects File "combined.py", line 122, in writeFunction File "openpyxl\cell.pyc", line 293, in _set_value File "openpyxl\cell.pyc", line 282, in bind_value File "openpyxl\cell.pyc", line 212, in set_value_explicit File "openpyxl\cell.pyc", line 185, in check_string UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 8770: ordin al not in range(128)
My code/program works perfectly when I do not freeze the binaries using py2exe so I do not understand what I am doing wrong. Below is the code
{{{ #!python
''' Created on Jun 29, 2011
@author: Timothy.Barrett ''' from openpyxl.reader.excel import load_workbook from openpyxl.workbook import Workbook import Tkinter from Tkinter import * import Tkinter, tkFileDialog from tkFileDialog import * import time import os import shutil import stat import subprocess from subprocess import call
class Logic: def init(self,frame): frame.geometry("600x500+30+30") self.setupSystem = Button(frame, text = "Run Initial Setup", command = lambda: self.setupSystemEndofDay()) self.setupSystem.place(x=10,y=10, width=125, height = 25) #self.openExcelButton = Button(frame, text = "Open Defect Excel", command = lambda: self.openExcelFile()) #self.openExcelButton.place(x=10, y=10, width=100, height=25) self.openTextButton = Button(frame, text = "Open Text", command = lambda: self.openTextFile()) self.openTextButton.place(x=10,y=38, width=100,height=25) self.startButton = Button(frame, text = "Start Program", command = lambda: self.loadDefects()) self.startButton.place(x=10,y=100, width=100,height=25)
self.updateStatVariable = StringVar()
self.status = Label(frame, textvariable= self.updateStatVariable, relief = RIDGE)
self.status.place(x=260,y=10,height=450,width=300)
self.helpDocs = "Please Read All Directions:\n\
To begin, Open QC and Follow the \n\'Extracting Data From QC Help File' \n\
once complete open the 'saving \n\
to proper format' help file\n\
once that is complete then you\n\
can start by pressing the initial setup button\n\
then open text button\n\
then finally start program\n\
once the process is done follow \n\
the on screen prompts to continue"
self.updateStatus(self.helpDocs)
def setupSystemEndofDay(self):
call("mkdir C:\\tempDir", shell = True)
#first open the excel file we are going to deal with
self.openExcelFileToCopy = tkFileDialog.askopenfilename(parent = root, title = "Open Defect Excel File")
self.pathToExcelFile = os.path.abspath(self.openExcelFileToCopy)
self.copyCommand = "copy " + '"' + self.pathToExcelFile + '"' + " C:\\tempDir"
call(self.copyCommand, shell = True)
self.copiedFileName = os.path.basename(self.pathToExcelFile)
self.updateStatus("Initial Setup Complete, \n press open Text button")
self.openExcelFile(self.copiedFileName)
def openExcelFile(self,excelFilePath):
self.openDefectExcelDialog = "C:/tempDir/"+excelFilePath
print self.openDefectExcelDialog
self.defectExcelFile = load_workbook(filename= self.openDefectExcelDialog)
self.defectExcelWorkbook = self.defectExcelFile.get_sheet_by_name('Defects')
#open script stopper workbook sheet
self.scriptStopperWorkbook = self.defectExcelFile.get_sheet_by_name('Script Stoppers')
def openTextFile(self):
self.openTextFileDialog = tkFileDialog.askopenfilename(parent = root, title= "Open Defect Comment File")
self.openStopTextDialog = tkFileDialog.askopenfilename(parent = root, title = "Open Script Stop Text")
self.writeEofCatchToFile()
def writeEofCatchToFile(self):
self.logFile = open("C:\\logFile.txt", "w")
self.addEOFStopToDefectFile = open(self.openTextFileDialog,"a")
self.addEOFStopToDefectFile.write("\nEOF")
self.addEOFStopToDefectFile.close
self.defectCommentsFile = open(self.openTextFileDialog, "r").readlines()
#open script stopper text file
self.addEOFStoptoStopFile = open(self.openStopTextDialog, "a")
self.addEOFStoptoStopFile.write("\nEOF")
self.addEOFStoptoStopFile.close
self.stopFile = open(self.openStopTextDialog, "r").readlines()
def writeFunction(self,keyword,rowIndex):
self.updateStatus("In Progress Hold On")
'''
function writes to log file
log file is read
data in log file is placed in defect comments column (11)
defect file is saved
continue
'''
nextIDValue = self.defectExcelWorkbook.cell(row = rowIndex+1, column = 2).value
nextIDValue = str(nextIDValue)
keyword = str(keyword)
newlist = []
innerCheckIndex = 0
for index in range (len(self.defectCommentsFile)):
self.percentage = index
newlist.append(self.defectCommentsFile[index].strip('\n'))
if keyword in self.defectCommentsFile[index]:
self.openLogFile = open("C:\logFile.txt", "w")
self.openLogFile.write("") #blanks the log file
self.openLogFile.close()
innerCheckIndex += index
while not "Defect ID: " in self.defectCommentsFile[innerCheckIndex] and not "EOF" in self.defectCommentsFile[innerCheckIndex] or not nextIDValue in self.defectCommentsFile[innerCheckIndex] and not "EOF" in self.defectCommentsFile[innerCheckIndex]:
self.openLogFile = open("C:\logFile.txt","a")
self.openLogFile.write(self.defectCommentsFile[innerCheckIndex]+"\n")
self.openLogFile.close()
innerCheckIndex += 1
self.openLogFile = open("C:\logFile.txt","r")
self.defectExcelWorkbook.cell(row = rowIndex, column = 11).value = self.openLogFile.read()
self.openLogFile.close()
innerCheckIndex = 0
newlist = []
for index in range (len(self.stopFile)):
newlist.append(self.stopFile[index].strip('\n'))
if keyword in self.stopFile[index]:
innerCheckIndex += index
if "Test:" in self.stopFile[innerCheckIndex] and not "EOF" in self.stopFile[innerCheckIndex]:
self.scriptStopperWorkbook.cell(row = rowIndex,column = 11).value = self.stopFile[innerCheckIndex]
innerCheckIndex += 1
innerCheckIndex = 0
def loadDefects(self):
rowIndex = 1
self.updateStatus("Starting The Process...Please wait a few moments")
while self.defectExcelWorkbook.cell(row = rowIndex, column = 2).value != None:
#send keyword and what row the keyword is in
self.writeFunction(self.defectExcelWorkbook.cell(row = rowIndex, column = 2).value, rowIndex)
rowIndex += 1
self.defectExcelFile.save(self.openDefectExcelDialog)
self.updateStatus("Process Complete. Check Excel File")
def updateStatus(self,statusCalculation):
statusCalculation = str(statusCalculation)
self.updateStatVariable.set(statusCalculation)
root = Tk() app = Logic(root) root.mainloop()
}}}