TypeError: expected str, bytes or os.PathLike object, not NoneType
Python error when you fail to set a value
The “not NoneType” is the clue with this error message. The particular function I called in this case is expecting a String (str), bytes (such as a file) or os.PathLike object which is a particular type of object you can instantiate that represents a file path.
If you see NoneType that means the variable you’re passing isn’t set to any value. You likely passed a variable to a function with hasn’t been set to any value. Alternatively, you tried to set it to a value, but the value you set it to was the NoneType because whatever you referenced to set it was None.
In my case, I tried to open a file with a file name argument that had not properly been set. I need to go back to where I set the file name and make sure I throw an error and stop the program if my file name is not set correctly.
If you liked this story please clap and follow:
Medium: Teri Radichel or Email List: Teri Radichel
Twitter: @teriradichel or @2ndSightLab
Requests services via LinkedIn: Teri Radichel or IANS Research
© 2nd Sight Lab 2022
Need Cloud Security Training? 2nd Sight Lab Cloud Security Training
Cybersecurity & Cloud Security Resources by Teri Radichel: Cybersecurity and Cloud security classes, articles, white papers, presentations, and podcasts