Repository: mitmproxy/mitmproxy

Issue:
Mitmweb can't run
When I run mitmweb,then open 121.0.0.1:8081, the error happened.

```
Traceback (most recent call last):
  File "/Users/venv.mitmproxy/lib/python2.7/site-packages/tornado/ioloop.py", line 1020, in _run
    return self.callback()
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 141, in tick
    flow.FlowMaster.tick(self, self.masterq, timeout=0)
  File "/Users/mitmproxy/libmproxy/flow.py", line 812, in tick
    return super(FlowMaster, self).tick(q, timeout)
  File "/Users/mitmproxy/libmproxy/controller.py", line 108, in tick
    self.handle(*msg)
  File "/Users/mitmproxy/libmproxy/controller.py", line 129, in handle
    m(obj)
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 167, in handle_request
    super(WebMaster, self).handle_request(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 990, in handle_request
    self.state.add_flow(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 561, in add_flow
    self.flows._add(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 469, in _add
    view._add(f)
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 23, in _add
    data=f.get_state(short=True)
  File "/Users/mitmproxy/libmproxy/models/flow.py", line 88, in get_state
    d = super(Flow, self).get_state(short)
  File "/Users/mitmproxy/libmproxy/stateobject.py", line 32, in get_state
    state[attr] = val.get_state(short)
  File "/Users/mitmproxy/libmproxy/models/connections.py", line 138, in get_state
    address={"address": self.address(),
TypeError: 'NoneType' object is not callable
ERROR:tornado.application:Exception in callback <bound method WebMaster.tick of <libmproxy.web.WebMaster object at 0x10cfe5a90>>
```

Mitmweb can't run
When I run mitmweb,then open 121.0.0.1:8081, the error happened.

```
Traceback (most recent call last):
  File "/Users/venv.mitmproxy/lib/python2.7/site-packages/tornado/ioloop.py", line 1020, in _run
    return self.callback()
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 141, in tick
    flow.FlowMaster.tick(self, self.masterq, timeout=0)
  File "/Users/mitmproxy/libmproxy/flow.py", line 812, in tick
    return super(FlowMaster, self).tick(q, timeout)
  File "/Users/mitmproxy/libmproxy/controller.py", line 108, in tick
    self.handle(*msg)
  File "/Users/mitmproxy/libmproxy/controller.py", line 129, in handle
    m(obj)
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 167, in handle_request
    super(WebMaster, self).handle_request(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 990, in handle_request
    self.state.add_flow(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 561, in add_flow
    self.flows._add(f)
  File "/Users/mitmproxy/libmproxy/flow.py", line 469, in _add
    view._add(f)
  File "/Users/mitmproxy/libmproxy/web/__init__.py", line 23, in _add
    data=f.get_state(short=True)
  File "/Users/mitmproxy/libmproxy/models/flow.py", line 88, in get_state
    d = super(Flow, self).get_state(short)
  File "/Users/mitmproxy/libmproxy/stateobject.py", line 32, in get_state
    state[attr] = val.get_state(short)
  File "/Users/mitmproxy/libmproxy/models/connections.py", line 138, in get_state
    address={"address": self.address(),
TypeError: 'NoneType' object is not callable
ERROR:tornado.application:Exception in callback <bound method WebMaster.tick of <libmproxy.web.WebMaster object at 0x10cfe5a90>>
```



Discussion:
Which version of mitmproxy/mitmweb are you running?

I am running the version which I downloaded from https://github.com/mitmproxy/mitmproxy.git three days ago

Which version of mitmproxy/mitmweb are you running?

I am running the version which I downloaded from https://github.com/mitmproxy/mitmproxy.git three days ago


Resolving patch:
diff --git a/libmproxy/models/connections.py b/libmproxy/models/connections.py
--- a/libmproxy/models/connections.py
+++ b/libmproxy/models/connections.py
@@ -135,8 +135,8 @@ def tls_established(self):
     def get_state(self, short=False):
         d = super(ServerConnection, self).get_state(short)
         d.update(
-            address={"address": self.address(),
-                     "use_ipv6": self.address.use_ipv6},
+            address=({"address": self.address(),
+                     "use_ipv6": self.address.use_ipv6} if self.address else {}), 
             source_address=({"address": self.source_address(),
                              "use_ipv6": self.source_address.use_ipv6} if self.source_address else None),
             cert=self.cert.to_pem() if self.cert else None


Test patch: