I see in your commits.

-            key_file = open(filename, "w")
+            if sys.version_info[0] < 3:
+                key_file = open(filename, "w")
+            else:
+                key_file = open(filename, "w", encoding="utf-8")

For another project, I discovered that in python 2.7 also has the encoding keyword. I don't know if there are not subtle differenbce between the two or not, but for that project, we could change those lines by

  key_file =, "w", encoding="utf-8")

An advantage of this was also that in python 2 you then get nice UnicodeDecodeErrors, while just using open can give strange errors if you eg open a windows utf-16 file (which in that project happens if a windows users saves csv files)..