UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

rv27783rv27783 Posts: 3

This is my code in Extension tool test :smile: from com.parasoft.api import *
from time import gmtime, strftime
from soaptest.api import *
from java.util import *
from org.apache.poi.hssf.usermodel import *
from java.io import FileInputStream
import sys
reload(sys)

encoding: utf-8

def setName(input, context):
OldExcelDT_PAID = context.getValue("ExcelFile","dt_paidOld")
NewDBDT_PAID = context.getValue("Generated Data Source","DT_PAID")
# Replaceing old values with new dcn values into delete_dcn_list.txt
file = open("H:\temp\report.xls", 'r')
filedata=file.read()
filedata = filedata.replace(OldExcelDT_PAID,NewDBDT_PAID)
f= open("H:\temp\report.xls","w")
f.write(filedata)
f.close()
file.close()
return (filedata)

-- I am getting below error
--Error Message:
DataSource: ExcelFile (row 1): Error during script execution. View Details for more information.

Traceback (most recent call last):

File "", line 17, in setName

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

-- How I can fix this. Basically I am updating Excel cell values to something new.

Comments

  • benken_parasoftbenken_parasoft Posts: 463 ✭✭✭
    edited May 2017

    It looks like you are trying to read and write an Excel file as if it were text and not binary (this won't work). Instead, if you are trying to use Apache POI library then I'd recommend looking over their how-to for proper usage: https://poi.apache.org/spreadsheet/how-to.html

    Using java libraries from Jython works but you may also want to consider using Groovy which has a more java-like API and syntax.

Sign In or Register to comment.