Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to resolve error in python - LookupError: unknown encoding: us-ascii

$
0
0

My Python Code:

import openpyxlpath = "C:\\Users\\abbc\\OneDrive - XYZ\\Desktop\\Output\\file.xlsx"target_workbook = openpyxl.load_workbook(path)target_sheet = target_workbook['Sheet1']target_sheet.cell(row=2, column=2, value = "111111")target_workbook.save(path)

The above piece of code gives me the error -LookupError: unknown encoding: us-ascii

The excel (.xlsx) file is a simple excel file with no data where im trying to write in a cell and save the workbook.

I have the py version - Python 3.11.4

I have tried many things but unable to get around the issue. It would be great if someone could point me in the right direction please.

Edit:Full Traceback

Traceback (most recent call last):  File "c:\Users\abbc\OneDrive - XYZ\Desktop\Integration_Recon\Code\tst2.py", line 10, in <module>    wb.save("file.xlsx")  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\workbook\workbook.py", line 386, in save    save_workbook(self, filename)  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 294, in save_workbook    writer.save()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 275, in save    self.write_data()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 77, in write_data    self._write_worksheets()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 215, in _write_worksheets    self.write_worksheet(ws)  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 200, in write_worksheet    writer.write()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\worksheet\_writer.py", line 361, in write    self.close()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\worksheet\_writer.py", line 369, in close    self.xf.close()  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\worksheet\_writer.py", line 289, in get_stream    with xf.element("worksheet", xmlns=SHEET_MAIN_NS):  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 144, in __exit__    next(self.gen)  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\et_xmlfile\xmlfile.py", line 50, in element    self._write_element(el)  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\site-packages\et_xmlfile\xmlfile.py", line 77, in _write_element    xml = tostring(element)          ^^^^^^^^^^^^^^^^^  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\xml\etree\ElementTree.py", line 1098, in tostring    ElementTree(element).write(stream, encoding,  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\xml\etree\ElementTree.py", line 731, in write    with _get_writer(file_or_filename, encoding) as (write, declared_encoding):  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 137, in __enter__    return next(self.gen)           ^^^^^^^^^^^^^^  File "C:\Users\abbc\AppData\Local\Programs\Python\Python311\Lib\xml\etree\ElementTree.py", line 794, in _get_writer    file = io.TextIOWrapper(file,           ^^^^^^^^^^^^^^^^^^^^^^LookupError: unknown encoding: us-ascii

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>