mutornadomon icon indicating copy to clipboard operation
mutornadomon copied to clipboard

Exception when ipaddress library is used

Open schultz9999 opened this issue 10 years ago • 3 comments

Seeing this when executing a request:

Uncaught exception
Traceback (most recent call last):
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/tornado/http1connection.py", line 238, in _read_message
    delegate.finish()
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/tornado/httpserver.py", line 289, in finish
    self.delegate.finish()
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/tornado/web.py", line 2022, in finish
    self.execute()
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/tornado/web.py", line 2043, in execute
    transforms = [t(self.request) for t in self.application.transforms]
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/mutornadomon/collectors/web.py", line 25, in _request
    if net.is_local_address(request.remote_ip):
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/mutornadomon/net.py", line 34, in is_local_address
    ip = IP(ip)
  File "/home/mycompany/myproject/env/local/lib/python2.7/site-packages/ipaddress.py", line 163, in ip_address
    ' a unicode object?' % address)
AddressValueError: '127.0.0.1' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?

Tracked down to net.py import statement:

try:
    import ipaddress
    Network = ipaddress.ip_network
    IP = ipaddress.ip_address
except ImportError:
    import ipcalc
    Network = ipcalc.Network
    IP = ipcalc.IP

If I have ipaddress installed, I see the error above and if ipcalc is used, it's all good.

schultz9999 avatar Jan 05 '16 20:01 schultz9999

Are you on Python 2 or Python 3?

Roguelazer avatar Jan 05 '16 20:01 Roguelazer

Python 2.7.10.

On Tue, Jan 5, 2016 at 12:21 PM, James Brown [email protected] wrote:

Are you on Python 2 or Python 3?

— Reply to this email directly or view it on GitHub https://github.com/uber/mutornadomon/issues/18#issuecomment-169120197.

schultz9999 avatar Jan 05 '16 20:01 schultz9999

Was this on 0.3.2? 0.3.3 should have fixed this with #15.

blampe avatar Mar 22 '16 21:03 blampe