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
Airflow:Passing a Dynamic Value to Sub Dag Operator
Find Row Where Values for Column Is Maximal in a Pandas Dataframe
How to Periodically Execute a Function With Asyncio
How to Keep Python Script Keep Running Indefinitely
A Better Way Than Looping and Calling Functions That Loop and Call Another Functions
Splitting Dataframe into Multiple Dataframes
Python: How to Escape Slashes in Path
Python/Pandas: Convert Month Int to Month Name
How to Get a Value from a Cell of a Dataframe
Converting Text File into Json in a Specific Format ( Python )
How to Share Single Sqlite Connection in Multi-Threaded Python Application
How to Enable Autocomplete (Intellisense) for Python Package Modules
Python Print First N Lines of String
How to Compile Multiple Python Files into Single .Exe File Using Pyinstaller
Formatting Datetime Xlabels in Matplotlib (Pandas Df.Plot() Method)
Correctly Reading Text from Windows-1252(Cp1252) File in Python
How to Get Max() to Return Variable Names Instead of Values in Python