You are getting this error, because your camera is not able to detect any face. It means when your program unable to find any face it throws an error because of null value.
To avoid this error, you can use if else condition in your python code. If it is not able to detect any face it will pass otherwise it will run your code.
Hope this will give you some idea how to avoid this error.