# Ctx.log.info in \_\_init\_\_

**URL:** https://discourse.mitmproxy.org/t/ctx-log-info-in---init--/326
**Category:** help
**Created:** [January 27, 2017, 10:10am UTC](https://discourse.mitmproxy.org/t/ctx-log-info-in---init--/326 "2017-01-27T10:10:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![xavierm02](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/xavierm02/32/105_2.png) [@xavierm02](https://discourse.mitmproxy.org/u/xavierm02)
#### Post date: [January 27, 2017, 10:10am UTC](https://discourse.mitmproxy.org/t/ctx-log-info-in---init--/326/1 "2017-01-27T10:10:51Z")

</div>

Hi,

I have a very weird error with the following code:

```
from mitmproxy import *
from mitmproxy.addons import *

class Dummy:
  def __init__ (self):
    print("print")
    ctx.log.info("log")

def start():
  return Dummy()

```

This is what I get:

```
$ mitmdump --script "problem.py" 2>&1 | head -n 30
Loading script: problem.py
print
log
Script error: TypeError: 'module' object is not callable

Script error: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 75, in scriptenv
    yield
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 161, in run
    return func(*args, **kwargs)
TypeError: 'module' object is not callable

During handling of the above exception, another exception occurred:

TypeError: 'module' object is not callable

Script error: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 75, in scriptenv
    yield
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 161, in run
    return func(*args, **kwargs)
TypeError: 'module' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 75, in scriptenv
    yield
  File "/usr/local/lib/python3.5/dist-packages/mitmproxy/addons/script.py", line 161, in run
    return func(*args, **kwargs)

```

The wird thing is that if I remove the `ctx.log.info` line, there is no exception. So somehow, this line causes an exception **after** doing what it’s supposed to do…

(I am using this because I’m making a “combiner” thing to combine several objects implementing `start()`, `stop()`. The way it works is that it registers things into `ctx.master.addons` on `start()` and removes them on `done()`. But since `done()` isn’t called when the script is reloaded, in the `start()` of my combiner, I store the instance in some global variable, and I call its done in ` __init__ ` if it’s still there. And since I log everything, I used log in ` __init__ ()` and that’s how I got that problem)

Thank you in advance for your help.

---

<div class="post-metadata">

### Author: ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)
#### Post date: [January 27, 2017, 10:00pm UTC](https://discourse.mitmproxy.org/t/ctx-log-info-in---init--/326/2 "2017-01-27T22:00:20Z")

</div>

The problem are your wildcard imports - if you replace them with just

```auto
from mitmproxy import ctx

```

things work as expected. I believe the problem is that `from mitmproxy import *` imports the `log` module, which coincidentally has the same name as the `log` event handler. As you do some logging, we try to invoke the `log` handler, which fails because it’s the module and not an event handler.
