The code snippet you have provided is correct for converting a string to bytes in Python using ASCII encoding.
However, the error message "At most 45 bytes at once" might be related to something else in your code or the specific function you're calling that requires the byte conversion.
Try the following :
test_string = "container/folder1/folder2/file.txt"
res = bytes(test_string, 'utf-8')