【问题标题】:File Reading Problems With Python [duplicate]Python的文件读取问题[重复]
【发布时间】:2017-11-05 19:53:53
【问题描述】:

我正在尝试读取文件,(密码列表),我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\ayden\Documents\2.1 Hacks\Python\PowerUp\FTPCracker.py", line 25, in <module>
    passwords = file.read()
  File "C:\Users\ayden\AppData\Local\Programs\Python\Python35-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 0x8f in position 1911885: character maps to <undefined>

是太大了还是有一些奇怪的不允许的字符?

【问题讨论】:

  • 您需要发布您的代码以获得更好的帮助!
  • 试试this: file = open(filename, encoding="utf8")
  • 确保在读取时设置编码='utf-8'

标签: python file


【解决方案1】:

检查文件的编码,然后在打开时指定。

例如,如果它是 UTF8 编码的,那么:

file = open(filename, encoding="utf8")

【讨论】:

  • 文本文件编码是“ANSI”,当我使用它时,它说编码类型无效。
  • 当我尝试 UTF-8 时,它显示“UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 5079963: invalid continuation byte”
  • 啊哈!我尝试了拉丁语 1 和繁荣!成功了,谢谢你的帮助:)
猜你喜欢
  • 1970-01-01
  • 2023-03-18
  • 2013-08-29
  • 2011-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多