Tapeworms are contracted when the reptile eats a food item or drinks water that is infected with a tapeworm egg. Which could happen in a variety of ways. If that is what you have here we won’t likely know for certain the source, and it could have been infected prior to you getting it. But the important thing is to get it treated so the snake can thrive and grow.