0
我正在嘗試使用腳本來檢查電子郵件是否存在。爲此,我使用DNS查詢。這是一個失敗的呼叫:查詢DNS時GAE超時
from dns import resolver
mx_data = resolver.query(hostname, 'MX', source='')
它的工作原理,如果我執行使用python腳本獨立的,但是當它的AppEngine運行在本地或遠程失敗。堆棧跟蹤:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/Users/user/dev/gaeapp/request.py", line 5827, in get
check2 = email_checker.validate_email(email)
File "/Users/user/dev/gaeapp/tools/email_checker.py", line 89, in validate_email
mx_data = resolver.query(hostname, 'MX')
File "/Users/user/dev/gaeapp/dns/resolver.py", line 974, in query
raise_on_no_answer, source_port)
File "/Users/user/dev/gaeapp/dns/resolver.py", line 894, in query
timeout = self._compute_timeout(start)
File "/Users/user/dev/gaeapp/dns/resolver.py", line 734, in _compute_timeout
raise Timeout
我有一個類似的問題的問題DNS query using Google App Engine socket但我試着打電話查詢與參數源=「」沒有成功。
我使用dnspython 1.11.1
UPDATE:它的工作原理後,手動設置DNS解析器:
r = resolver.Resolver()
r.nameservers = ['8.8.8.8', '8.8.4.4']
mx_data = r.query(hostname, 'MX')
一個顯而易見的問題是您使用的是哪種解析器?查看代碼resolver.query將調用get_default_resolver()您是否已經建立了解析器列表,如果這些從解釋器的角度來看是有意義的? –
@TimHoffman這是一個很好的觀點。我已經將Google DNS服務器添加爲解析器,並且可以正常工作。 – dablak