wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

mitmproxy backend raises TypeError: 'NoneType' object is not callable #134

Closed wkeeling closed 3 years ago

wkeeling commented 4 years ago

Occasionally the mitmproxy backend raises the following exception. It seems to happen at the end of a test when Selenium Wire shuts down the backend when the backend is still processing requests.

The exception seems harmless although it would be nice to prevent it from happening.

INFO:seleniumwire.proxy.client:Destroying proxy
Traceback (most recent call last):
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/server.py", line 121, in handle
    root_layer()
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/modes/http_proxy.py", line 9, in __call__
    layer()
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/tls.py", line 285, in __call__
    layer()
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/http1.py", line 83, in __call__
    layer()
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/http.py", line 190, in __call__
    if not self._process_flow(flow):
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/http.py", line 262, in _process_flow
    return self.handle_regular_connect(f)
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/http.py", line 208, in handle_regular_connect
    layer()
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/protocol/tls.py", line 285, in __call__
    layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
Traceback (most recent call last):
  File "/home/will/Development/environments/selenium-wire/lib/python3.6/site-packages/mitmproxy/proxy/server.py", line 121, in handle
    root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
LpZ-squall commented 3 years ago

I experience the same issue. It seems to happen when calling quit() on the driver, 50% of the times in my setup. It is not a really big deal but still quite annoying. Do you think we should open an issue in the mitmproxy project, or is it a selenium-wire bug?

Thanks for your work on selenium-wire by the way, this is awesome!

wkeeling commented 3 years ago

Quitting the driver will now wait for silence (wait for requests to complete) before mitmproxy is shutdown, which should significantly reduce the frequency of these messages. They may still happen occasionally when very slow requests don't complete before the shutdown timeout (5 seconds) is reached. It is also worth mentioning that the default backend has been reworked from v4.0.0 of Selenium Wire, which removes many reasons for switching to the mitmproxy backend in the first place.