Jump to content

Python: Error on Module Run for File Conversion

Go to solution Solved by Azgoth 2,

I haven't looked at the file, but I run into errors like this from time to time.  Try changing all of your open() functions to include the encoding="UTF8" argument.  Python says it opens with UTF-8 encoding by default, but I find that sometimes not specifying the encoding causes errors like this, and specifying the file encoding often solves the issue for me.

 

Also, just as a note, I recommend using the with context manager keyword for dealing with files.  It helps protect against weird things happening that might accidentally cause the file to be left open, which can sometimes cause issues further down a program.

Greetings,

 

I am encountering an error upon running a script which allows users to select multiple viscosity (.visz) files to convert to OpenVPN (.ovpn) files.

Error:

Traceback (most recent call last):
  File "C:/Users/Name/Desktop/test.py", line 18, in <module>
    for line in f:
  File "C:\Users\Name\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 45: character maps to <undefined>

 

 

 

CPU - I7 4770k @ 4.3GHz GPU - EVGA Nvidia GeForce GTX 780 Motherboard - ASUS Maximus VI Extreme RAM - 16GB of Corsair Dominator Platinum @ 2133MHz  Case - Corsair 800D PSU - Corsair AX1,200i CPU Cooler - Custom Liquid CPU Cooler SSD - Samsung 840 Pro 256GB Hard Drive - Western Digital Black 1TB.

Link to comment
Share on other sites

Link to post
Share on other sites

I haven't looked at the file, but I run into errors like this from time to time.  Try changing all of your open() functions to include the encoding="UTF8" argument.  Python says it opens with UTF-8 encoding by default, but I find that sometimes not specifying the encoding causes errors like this, and specifying the file encoding often solves the issue for me.

 

Also, just as a note, I recommend using the with context manager keyword for dealing with files.  It helps protect against weird things happening that might accidentally cause the file to be left open, which can sometimes cause issues further down a program.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×