Why Am I Getting Ioerror: [Errno 13] Permission Denied

IOError: [Errno 13] Permission denied: How to fix it?

It looks like you're trying to save the file into your root (/) directory and you probably won't have permission there. Save it to some other place.

IOError: [Errno 13] Permission denied How do I fix this?

Script has no permission to write into log file. Changing chmod of tmp/anpr_log should fix your issue:

sudo chmod +rw /tmp/anpr_log

Why am I getting [Errno 13] Permission denied: when making consecutive open and write calls?

Thanks to some commentors, I've found that nesting with open() outside of iterparse() does the trick.

My antivirus program was likely the culprit, accessing the file each time it was closed, which occasionally caused an access conflict on the next file open operation.

I didn't like opening and closing the file for each element because of the operation cost, and I originally had parsed the XML from within the file open when I was writing to a single file. But, when I decided to write to multiple files, I didn't want to parse the XML over again for each JSON file I wanted to write from it.

Seems like a no-brainer now, but nesting file opens works and saves compute. It might build up the indents if you want to write a lot of files, but c'est la vie.

def process_map(file_in, fo_pre, mode = "a"):

with codecs.open(fo_pre+"_nodes.json", mode) as nd_fo, \
codecs.open(fo_pre+"_ways.json", mode) as wy_fo, \
codecs.open(fo_pre+"_relations.json", mode) as rl_fo:

for _, element in ET.iterparse(file_in):
el = shape_element(element)
if el:
if el["doc_type"] == "node":
write_el(el=el, file_out=fo_pre+"_nodes.json",
mode=mode)
elif el["doc_type"] == "way":
write_el(el=el, file_out=fo_pre+"_ways.json",
mode=mode)
elif el["doc_type"] == "relation":
write_el(el=el, file_out=fo_pre+"_relations.json",
mode=mode)

return


Related Topics



Leave a reply



Submit