PYTHON-3800 Add lower() to node when validate hosts of srv records #1289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
When using
mongodb+srv
DNS Seed List Connection String, I had no problems with the other drivers, but only when using the pymongo driver.The error is as follows
It was weird that it only happened with the python driver.
Cause
First, the
uri
in the connection string that I was using contained uppercase letters, and the SRV Records also contained uppercase letters.For example,
mongodb+srv://username:password@mongodb-jeongmu-rs.RegionOne.mg.db.***.com
If you look at line 144 of
uri_parser.py
, inside theparse_host
function, the hostname is converted to lowercase via lower(), but the imported SRV records still contain uppercase letters.Therefore, when comparing the fqdn and node at
_get_srv_response_and_hosts
, the fqdn has been changed to lowercase and the node still contains uppercase letters.It cause
pymongo.errors.ConfigurationError: Invalid SRV host
.