pymongo ipv6

`host` (optional): hostname or IP address or Unix domain socket
  path of a single mongod or mongos instance to connect to, or a
  mongodb URI, or a list of hostnames / mongodb URIs. If `host` is
  an IPv6 literal it must be enclosed in '[' and ']' characters
  following the RFC2732 URL syntax (e.g. '[::1]' for localhost).
  Multihomed and round robin DNS addresses are **not** supported.

上面是pymongo的MongoClient的初始化方法的doc文档对于host的解析其中提到host是ipv6格式,则需要遵循RFC2732中的URL语法标准,URL地址应该用“[”和“]”字符括起来。

参考文档:RFC2376官方文档

举例:

IPv6 addresses:

      FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
      1080:0:0:0:8:800:200C:4171
      3ffe:2a00:100:7031::1
      1080::8:800:200C:417A
      ::192.9.5.5

转换后:
[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]
[1080:0:0:0:8:800:200C:417A]
[3ffe:2a00:100:7031::1]
[1080::8:800:200C:417A]/foo
[::192.9.5.5]

猜你喜欢

转载自blog.csdn.net/qq_35462323/article/details/85339411
今日推荐