Hi saurabh pophare,
Glad to see you resolve the issue posting it as an answer to help other community members.
pymongo.errors.ServerSelectionTimeoutError: encoding with 'idna' codec failed (UnicodeError: label too long)
The error can cause because of many reasons but one of the reasons is if you have special characters like @,/
in your username and password these need to be escaped before it could be used normally.
special characters such as those that may be used in the user and password need to be URL encoded to be parsed correctly. This includes the @ sign.
Below is an example :
Here password : "kx@jj5/g", where the "@" sign and "/"characters are Present
Which can be escaped bu repenteng
%40
as @ and%2F
as / respectively
Reference : https://blog.csdn.net/qq_41878442/article/details/141337484
Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.