gera2ld / async_dns

DNS library based on asyncio
MIT License
70 stars 17 forks source link

Example in the README does not work #15

Closed covuworie closed 4 years ago

covuworie commented 4 years ago

Hi,

This library seems to have some very good functionality and I am looking into incorporating it into a project of mine. However, I'm struggling to get the example that you have in the README to even work:

import asyncio
from async_dns import types
from async_dns.resolver import ProxyResolver

loop = asyncio.get_event_loop()
resolver = ProxyResolver()
res = loop.run_until_complete(resolver.query('www.baidu.com', types.A))
print(res)

I get a value of None returned when I paste the code into the following online REPL: https://repl.it/repls/CoordinatedLameCoins

You can see the versions of python and pypi libraries being used in the pyproject.toml. Even when I edit the file to force the use of the latest version (1.0.9) I get the same result.

Also, even if I change the domain name to google.com, facebook.com etc. the same None result is returned.

Am I missing something here?

gera2ld commented 4 years ago

The ProxyResolver uses 8.8.8.8, 8.8.4.4 as its name servers by default. However the environment you are trying to use does not work with them. A quick workaround in your case is to use the system nameservers instead:

from async_dns import get_nameservers

resolver = ProxyResolver(proxies=get_nameservers())
covuworie commented 4 years ago

Thanks @gera2ld, this seems to have fixed the issue. It's strange as I thought that I had used aiodns before in that environment with remote nameservers. But I tried that also again and it failed.

I'll probably do some other tests in a docker container or virtual environment on my machine so I don't have this issue again.

A quick question. Are there any plans to return errors when a domain name is not found, or the server fails, or there is a timeout etc.? At the moment None is returned which doesn't give much information.

gera2ld commented 4 years ago

Are there any plans to return errors when a domain name is not found, or the server fails, or there is a timeout etc.?

Not yet but perhaps there should be. This project was designed to simply provide a DNS service at the beginning and the APIs are not well designed.

covuworie commented 4 years ago

I see what you are saying. However, the design of the API is not actually as as bad as you say. You've done a good job making the API very concise. I've had a lot of experience designing APIs in the past and good APIs are hard to design. The main thing missing is documentation of the methods, parameters / arguments and responses.

Possibly the responses could be split out into their own classes. But I think more comprehensive documentation and clear naming would probably make this less essential. It took me a bit of time to work out the responses depending on the name servers I was using (tld vs authoritative) and required me to understand quite a bit about the DNS system.