@Akshin17
Пайтон програмист

Ошибка cp1251.py?

c = 1

with open(r'C:\Users\AKSHIN\Downloads\errr.txt','r',encoding='utf-8')as f:
	z = f.read().split('\n')
	print(z)


ошибка

Traceback (most recent call last):
File "C:\Users\AKSHIN\Desktop\python\chtoto.py", line 5, in
print(z)
File "C:\Users\AKSHIN\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in position 1302053: character maps to
[Finished in 0.4s with exit code 1]
[shell_cmd: py -3 -OO -u "C:\Users\AKSHIN\Desktop\python\chtoto.py"]
[dir: C:\Users\AKSHIN\Desktop\python]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Users\AKSHIN\PycharmProjects\akshin\regchecker\insta\geckodriver.exe;C:\Users\AKSHIN\AppData\Local\Programs\Python\Python38-32;]
  • Вопрос задан
  • 1478 просмотров
Пригласить эксперта
Ответы на вопрос 1
hottabxp
@hottabxp Куратор тега Python
Сначала мы жили бедно, а потом нас обокрали..
Можно обработать данное исключение:
with open(r'C:\Users\AKSHIN\Downloads\errr.txt','r',encoding='utf-8')as f:
  z = f.read().splitlines()
  for line in z:
  	try:
  		print(line)
  	except UnicodeEncodeError:
  		pass
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы