Bugs That Bite
Published in

Bugs That Bite

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.

Teri Radichel

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



Cybersecurity for Executives in the Age of Cloud on Amazon

Need Cloud Security Training? 2nd Sight Lab Cloud Security Training

Is your cloud secure? Hire 2nd Sight Lab for a penetration test or security assessment.

Have a Cybersecurity or Cloud Security Question? Ask Teri Radichel by scheduling a call with IANS Research.

Cybersecurity & Cloud Security Resources by Teri Radichel: Cybersecurity and Cloud security classes, articles, white papers, presentations, and podcasts



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store