0

The whois module does not seem to work for me, running this code gives me an error

import whois
domains = ['cnn.com']
for dom in domains:
    domain = whois.Domain(dom)
    print domain.registrar 

This throws this error:

Traceback (most recent call last):
File "C:\Python27\Practice\2.py", line 5, in
domain = whois.Domain(dom)
File "C:\Python27\lib\site-packages\whois_3_adjust.py", line 12, in init
self.name = data['domain_name'][0].strip().lower()
TypeError: string indices must be integers, not str

Tried this query as well:

import whois
var = whois.query('google.com')
print var

C:\Python27\python.exe C/Test.py
Traceback (most recent call last):
  File "C:/Test.py", line 2, in <module>
    var = whois.query('google.com')
  File "C:\Python27\lib\site-packages\whois\__init__.py", line 50, in query
    pd = do_parse(do_query(d, force, cache_file, slow_down, ignore_returncode), tld)
  File "C:\Python27\lib\site-packages\whois\_1_query.py", line 44, in do_query
    _do_whois_query(dl, ignore_returncode),
  File "C:\Python27\lib\site-packages\whois\_1_query.py", line 58, in _do_whois_query
    p = subprocess.Popen(['whois', '.'.join(dl)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "C:\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 959, in _execute_child
    startupinfo)
WindowsError: [Error 2] 

Process finished with exit code 1
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Can you add the error output you are getting? Also - what do you mean by "did not work as well"? What was the issue or difference? You can respond in a comment, but please update the question with "edit" to clarify whenever possible. – LightCC Oct 12 '17 at 21:34
  • Also please read the documentation at this site https://github.com/nri-pl/python-whois – rgk Oct 12 '17 at 21:35
  • @LightCC wrote the second error. thank you for your comment – PyBeginner Oct 12 '17 at 21:40
  • You want `whois.query(url)`, not `whois.whois(url)` – ottomeister Oct 13 '17 at 00:42
  • @ottomeister query also fails edited again – PyBeginner Oct 13 '17 at 07:51
  • Ugh. The module is trying to execute an external program called `whois`, but that command does not exist on your system -- or at least, it doesn't exist in a directory that's in your `%PATH%`. You could try installing the `whois` command from https://learn.microsoft.com/en-us/sysinternals/downloads/whois but I don't know whether this Python module will understand the format of the output of that version of `whois`. – ottomeister Oct 13 '17 at 19:59

0 Answers0