def process_file(self):
error_flag = 0
line_count = 0
log_file = self.file_name
pure_name = log_file.strip()
# print('Before opening file ',pure_name)
logfile_in = open(pure_name, 'r') # Read file
lines = logfile_in.readlines()
# print('After reading file enteries ', pure_name)
Error Message
Traceback (most recent call last):
File "C:\Users\admin\PycharmProjects\BackupLogCheck\main.py", line 49, in <module>
backupLogs.process_file()
File "C:\Users\admin\PycharmProjects\BackupLogCheck\main.py", line 20, in process_file
lines = logfile_in.readlines()
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\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 0x90 in position 350: character maps to <undefined>
Process finished with exit code 1
Line 49 is where I call above method. But I have traced that it crashes at reading the file. I have checked the file; it has just text in it. I don't know if there are some characters which it doesn't like on reading entries. I am running on Windows 10.
I am new to Python, any suggestion how to find/correct the issue?
Try the file name in string format
logfile_in = open('pure_name', 'r') # Read file
lines = logfile_in.readlines()
print(lines)
output
['test line one\n', 'test line two']
or
logfile_in = open('pure_name', 'r') # Read file
lines = logfile_in.readlines()
for line in lines:
print(line)
output
test line one
test line two
I am trying to convert a JSON file into a CSV file. My code is down below. However, I keep getting this error:
Traceback (most recent call last):
File "C:\Users\...\PythonParse.py", line 42, in <module>
writer.writerow(data)
File "C:\Documents and Settings\...\Python37\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 38409-38412: character maps to <undefined>
import json
import gzip
import csv
outfile = open("VideoGamesMeta.csv","w")
writer = csv.writer(outfile)
data = []
items = []
names = []
checkItems = False;
checkUsers = False;
numItems = []
numUsers = []
for line in open("meta_Video_Games.json","r",encoding="utf-8"):
results = (json.loads(line))
if 'title' in results:
if 'asin' in results:
name = results['title']
item = results['asin']
data = [item,name]
writer.writerow(data)
items.append(item)
names.append(name)
In a long script I have this lines
document.contents = codecs.decode(document.contents.encode("ascii"), "uu")
where document.contents is a str. This line produces the following error:
Traceback (most recent call last):
File "/usr/lib/python3.7/encodings/uu_codec.py", line 54, in uu_decode
data = binascii.a2b_uu(s)
binascii.Error: Illegal char
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/encodings/uu_codec.py", line 58, in uu_decode
data = binascii.a2b_uu(s[:nbytes])
binascii.Error: Illegal char
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "3_extract_embedded.py", line 28, in <module>
myfile = filings_extractor.extract(txt_file).save(extracted_dir)
File "/media/raffaele/DATA/data/progetti_miei/edgardown/FilingsExtractor.py", line 180, in extract
document.contents = codecs.decode(document.contents.encode("ascii"), "uu")
binascii.Error: decoding with 'uu' codec failed (Error: Illegal char)
The problem is that I don't get the error if I try to save it on a file
with open("to_decode.uu", "wb") as fileh:
fileh.write(document.contents.encode("ascii"))
uu.decode("to_decode.uu", "to_decode.jpeg")
and I cannot produce a MWE, as a MWE with the exact string works without problems:
instr = r"""begin 644 logo.jpg
M_]C_X``02D9)1#`!`#``9`!D``#_[``11'5C:WD``0`$````9```_^X`#D%D
M;V)E`&3``````?_;`(0``0$!`0$!`0$!`0$!`0$!`0$!`0$!`0$!`0$!`0$!
M`0$!`0$!`0$!`0$!`0("`#("`#("`#("`P,#`P,#`P,#`P$!`0$!`0$"`0$"
M`#(!`#(#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#
M`P,#`P,#`P,#_\``$0#`5`![`P$1``(1`0,1`?_$`+8```$$`P$!`0``````
M```````&!P#)`P0%`0(*`0$``00#`0$`````````````!#4'"`D!`P0""A``
M`0,#`P(%`08$!P$``````0(#!``1!2$2!C$'05$B$PAA<8$R(Q0)H;%2,Y'!
M\4)B)!5#$0`!`#0$`P0&!P0$#P`````!`#,`$00%(1(&!S%!46$B$PAQ#9&A
M,A2QP=%"(S,)\'(5%N&"DK)28L+2XD-3#Y.CTR1$)1C_V#`,`P$``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N
M+[B:N#9-E=O=/D.VVE":#<SF]OQ$1#KON/JR^(/S[W?/20]\IP^>-Q..QS2&
MXN.AP`W<-)B,,LI;0"+(2&4)&TVJXU!2JHVBR99`<)=(ACM0_4J\2H)*^TSC
MJJ())%>Z.J/*0#I""D(*0#I""D(*0#I""D(*0#I""D(*0#I""D(*0#I""D(*
*0#I""D(*0C__V3\_
`
end
"""
import uu
import codecs
with open("to_decode.uu", "w", encoding="ascii") as fileh:
fileh.write(instr)
uu.decode("to_decode.uu", "decoded.jpeg")
# Use codecs package
outstr = codecs.decode(instr.encode("ascii"), "uu")
with open("decoded2.jpeg", "wb") as fileh:
fileh.write(outstr)
I am trying to use a file to read ip addresses and then find out corresponding location of that address
import IP2Location;
IP2LocObj = IP2Location.IP2Location();
IP2LocObj.open("data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN");
#t=open('output.txt','w');
t=open('test_ip','r');
Line=t.readline();
While line:
rec = IP2LocObj.get_all(Line);
Line=t.readline();
print rec.country_short
error is coming here
Traceback (most recent call last):
File "myprogram.py", line 8, in <module>
rec = IP2LocObj.get_all(t);
File "/home/networkgroup/Downloads/IP2Location-Python-master/IP2Location.py", line 219, in get_all
return self._get_record(addr)
File "/home/networkgroup/Downloads/IP2Location-Python-master/IP2Location.py", line 364, in _get_record
ipv = self._parse_addr(ip)
File "/home/networkgroup/Downloads/IP2Location-Python-master/IP2Location.py", line 357, in _parse_addr
socket.inet_pton(socket.AF_INET, addr)
TypeError: inet_pton() argument 2 must be string, not file
This code is giving error.You can check out the sample code here http://www.ip2location.com/developers/python
Please try the new Python codes below.
import IP2Location;
IP2LocObj = IP2Location.IP2Location();
IP2LocObj.open("IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-SAMPLE.BIN"); # This is sample database
with open('test_ip.txt') as f: # file containing ip addresses
for line_terminated in f:
line = line_terminated.rstrip('\r\n'); # strip newline
if line: # non-blank lines
print line
rec = IP2LocObj.get_all(line);
print rec.country_short