0

So, i'm trying to write something, but the interpreter throws this:

Traceback (most recent call last):
  File "C:\superbad_backup\SuperBad Backup\www.superbad.com\scanner.py", line 21, in <module>
    scan_path(i)
  File "C:\superbad_backup\SuperBad Backup\www.superbad.com\scanner.py", line 12, in scan_path
    for i1 in current_file.readlines():
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python37-32\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 0x8d in position 56: character maps to <undefined> 

The string i'm feeding it is "C:\superbad_backup\SuperBad Backup\www.superbad.com\submit"

Should i give up on this entirely, use another library or i'm being dumb?

EDIT: People are asking the code, so here is my spaghetti monster.

from os import listdir, chdir, getcwd
from os.path import isdir, dirname

dir_list = []

def scan_path(path):
    for i in listdir(path):
        if isdir(i):
            dir_list.append(getcwd()+"\\"+i)
        elif isdir(i) == False:
            current_file = open(i)
            for i1 in current_file.readlines():
                if "onMouseOver" in i1 and ".gif" in i1 or "onMouseOver" in i1 and ".png" or "onMouseOver" in i1 and ".jpg" or "onMouseOver" in i1 and ".jpeg" in i1:
                    print(i)
                    break

scan_path("C:\\superbad_backup\\SuperBad Backup\\www.superbad.com")

for i in dir_list:
    chdir(i)
    print(i)
    scan_path(i)
    dir_list.remove(i)

  • There is a character `\x8d` somewhere. Can you please show a hex dump of that section of the file? – Tim Dec 01 '20 at 02:32
  • Please show the code you are running. Also: https://stackoverflow.com/questions/12213178/python-traceback-codecs-charmap-decodeinput-self-errors-decoding-table0 – Tim Dec 01 '20 at 02:35
  • @Tim Well, i tried the answer, but it didn't work, so i'll just send the whole code. – Caio Francisco Dec 01 '20 at 02:48
  • What about if you do, `current_file = open(i, 'rb')`, and then change all your string to be like `if b"onMouseOver" in i1`? Also, that line is pretty hard to understand and should be split into multiple statements on multiuple lines ... or just ... `image_exts = [".gif", ".jpg", ".png"]` then `if "onMouseOver" in i1 and any([ext in i1 for ext in image_exts]):` – Tim Dec 01 '20 at 03:04
  • Well, that fixed the issue. Thanks! – Caio Francisco Dec 01 '20 at 03:10

0 Answers0