用于aiohttp的https reslover上的dns
aiohttp-doh的Python项目详细描述
用于aiohttp的https reslover上的dns
安装
$ pip install aiohttp-doh
手动使用
如果要手动使用,则必须在^{tt2}中导入ClientSession。$ 模块和TCPConnector在aiohttp.connector模块和^{tt5}中$ 在aiohttp_doh包中。
fromaiohttp.clientimportClientSessionfromaiohttp.connectorimportTCPConnectorfromaiohttp_dohimportDNSOverHTTPSResolverdefmy_client_session(*args,**kwargs):resolver=DNSOverHTTPSResolver(endpoints=['https://cloudflare-dns.com/dns-query',])connector=TCPConnector(resolver=resolver)returnClientSession(*args,**kwargs,connector=connector)asyncdefmain():asyncwithmy_client_session()assession:asyncwithsession.get('http://example.com')asresp:data=awaitresp.text()print(data)
快捷方式
手工操作太繁琐了。所以我做捷径用起来很方便。 您只需将aiohttp.ClientSession替换为aiohttp_doh.ClientSession。
fromaiohttp_dohimportClientSessionasyncdefmain():asyncwithClientSession()assession:asyncwithsession.get('http://example.com')asresp:data=awaitresp.text()print(data)
选项
您可以为配置传递以下参数。
- 端点
- https端点上的str.dns列表。 快捷方式使用'https://dns.google.com/resolve' 和'https://cloudflare dns.com/dns query'默认都是。 你也可以用其他的来代替。
- json加载
- 用于加载json的函数。默认值是python内置json模块的一个。 您可以使用第三方json库,如simplejson或ujson。
- 分解器类
- 内部DNS解析程序类。用于连接到终结点。 默认值为aiohttp default。
许可证
麻省理工学院