elastic / apm-agent-python

https://www.elastic.co/guide/en/apm/agent/python/current/index.html
BSD 3-Clause "New" or "Revised" License
414 stars 220 forks source link

__init__() got an unexpected keyword argument 'assert_hostname' #570

Closed kh2901 closed 5 years ago

kh2901 commented 5 years ago

After upgrading to Version 5.1.1 (recent version 4.2.1) the flask app running on below error:

Traceback (most recent call last):
  File "\elasticapm\transport\http.py", line 79, in send
    "POST", url, body=data, headers=self._headers, timeout=self._timeout, preload_content=False
  File "\urllib3\poolmanager.py", line 324, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "\elasticapm\instrumentation\packages\base.py", line 136, in call_if_sampling
    return wrapped(*args, **kwargs)
  File "\elasticapm\instrumentation\packages\base.py", line 136, in call_if_sampling
    return wrapped(*args, **kwargs)
  File "\urllib3\connectionpool.py", line 588, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "\urllib3\connectionpool.py", line 248, in _get_conn
    return conn or self._new_conn()
  File "\urllib3\connectionpool.py", line 209, in _new_conn
    strict=self.strict, **self.conn_kw)
  File "\urllib3\connection.py", line 114, in __init__
    _HTTPConnection.__init__(self, *args, **kw)
TypeError: __init__() got an unexpected keyword argument 'assert_hostname'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "\elasticapm\transport\base.py", line 208, in _flush
    self.send(data)
  File "\elasticapm\transport\http.py", line 92, in send
    raise TransportException(message, data, print_trace=print_trace)
elasticapm.transport.base.TransportException: Unable to reach APM Server: __init__() got an unexpected keyword argument 'assert_hostname' (url: http://<apm-server url>:8200/intake/v2/events)

The NO_PROXY env variable is used.

To Reproduce

  1. apm.init_app()
  2. Running on TransportException

Expected behavior: Connect to apm-server host and add apm data.

Environment (please complete the following information)

Additional context

Add any other context about the problem here.

basepi commented 5 years ago

Looks like we're passing the assert_hostname pieces for cert validation even for http, where certs are definitely not relevant. I'm looking into it.

basepi commented 5 years ago

Ah, I think I see the problem. Can you try removing your 'VERIFY_SERVER_CERT': False, config? I think the issue you're seeing is due to combining https config values with an http SERVER_URL. If removing that config value fixes the error, then it's still a bug but I can verify that I've diagnosed the issue correctly.

basepi commented 5 years ago

(I also have a sneaking suspicion that this error would be present in 4.2.1, but that your prod 4.2.1 instance is using https, while this development instance is using http. Basically, I think this is an old bug triggered by a new config change, not a new bug in the new version. Still good to get it fixed!)

kh2901 commented 5 years ago

Ah, I think I see the problem. Can you try removing your 'VERIFY_SERVER_CERT': False, config? I think the issue you're seeing is due to combining https config values with an http SERVER_URL. If removing that config value fixes the error, then it's still a bug but I can verify that I've diagnosed the issue correctly.

@basepi Thank you this fixed the problem.

basepi commented 5 years ago

Awesome! The linked PR will also fix this so you won't have to worry about it in the future.