Python Find & Replace WorkspacePaths

I have created a python script that lists all the mxds within a folder directory and then replaces the workspace paths. Now it works correctly for the majority of mxds but on a couple of the mxds it is failing to to replace the workspace path. I would appreciate any advice. I have copied the code into this question but also attached the code. Please note I have more than 1 database connection hence why there is the two find and replace lines for the two connections.