secynic / ipwhois

Retrieve and parse whois data for IPv4 and IPv6 addresses
https://ipwhois.readthedocs.io/en/latest
BSD 2-Clause "Simplified" License
556 stars 121 forks source link

python 3.8 error: TypeError: unsupported operand type(s) for *: 'OpenerDirector' and 'int' #313

Closed mahesh557 closed 1 month ago

mahesh557 commented 3 years ago

HI,

Getting below error in python3.8. Can you please help fix this.

  File "/Volumes/Macintosh HD - Data/ContentDev/MySOAR/venv/lib/python3.8/site-packages/ipwhois/asn.py", line 455, in lookup
    self._net.dns_resolver.timeout * (
TypeError: unsupported operand type(s) for *: 'OpenerDirector' and 'int'

My Code

    import urllib
    from ipwhois import IPWhois

    proxies = get_systemproxy()                #return proxy dict{'http': .., 'https':...}
    proxy_url = proxies.get('https') if proxies.get('https') else proxies.get('http')
    if proxy_url != '':
        proxy_handler = urllib.request.ProxyHandler(proxies)
        proxy_opener =  urllib.request.build_opener(proxy_handler)
        ip_obj = IPWhois(ip, proxy_opener)
    else:
        ip_obj = IPWhois(ip)

    results = ip_obj.lookup_rdap(depth=1)

Problem at /ipwhois/asn.py line 455, is self._net.dns_resolver.timeout is of type OpenerDirector instead of float/int

                    self._net.dns_resolver.lifetime = (
                        self._net.dns_resolver.timeout * (
                            retry_count and retry_count or 1
                        )
                    )
secynic commented 1 month ago

@mahesh557 You are passing the 2nd argument as a proxy opener rather than the expected timeout. That is expected as the third argument. I would suggest passing as keyword args like: ip_obj = IPWhois(address=ip, timeout=30, proxy_opener=proxy_opener)