for i in range(pw_length):
pwd = pwd + secrets.choice(alphabet)
But ... that's a very inefficient way to generate it - there is no guarantee that the random sequences generated will ever meet the criteria which allows it to return a password, particularly as the length drops.
There are two ways to fix that: generate three indexes - one for a special character, two for digits. As you loop through the "create a password loop, check the current index: if it matches the special character index, add one of those. If it matches one of the digit indexes, add one of those. Otherwise, add a letter.
That way, the resulting string will always meet the criteria, and the generation time will be consistent.