Skip to content

Exception when ipaddress library is used #18

@schultz9999

Description

@schultz9999

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions