Error- expected string or byte like object

The code worked fine initially but then started throwing Error - expected string or bytes-like object