What’s the purpose of the line:
board_buid.flash_mode = dout
Do you have a special board?
Things to try:
- Remove the
board_buid.flash_modeline - Ensure no serial monitor is open and blocking the connection
- Lower the
upload_speedto 9600 (you can increase it again later)