apm-agent-python icon indicating copy to clipboard operation
apm-agent-python copied to clipboard

ValueError, Can't set ELASTIC_APM_SERVER_URL as "url:port" with aiohttp since new update of python yarl librairy

Open thetintin1000 opened this issue 1 year ago • 3 comments

Describe the bug: Can't use ELASTIC_APM_SERVER_URL = "url:port" when building elastic apm instance from aiohttp app since new url control have been added on Yarl dependent library.

To Reproduce

  1. Intall dependencies
  2. configure aiohttp web app with global variable ELASTIC_APM_SERVER_URL = "url:port"
  3. build ElasticAPM(app) instance app as a aiohttp web app.
  4. raises a ValueError from yarl python library because of the format "url:port" not allowed (since yarl 1.13)

Environment (please complete the following information)

  • OS: linux
  • Python version: 3.12.7
  • aiohttp : "3.10.5"
  • elastic-apm = "6.23.0"

Additional context Error: File "/home/nonroot/venv/lib/python3.12/site-packages/yarl/_url.py", line 1607, in _host_validate\n raise ValueError(\nValueError: Host 'X.X.X.X:8080' cannot contain ':' (at position 11)"

When downgrading yarl to 1.12.1, it's now working again.

thetintin1000 avatar Oct 14 '24 09:10 thetintin1000

Strange, yarl 1.13.0 is able to parse urls just fine here:

$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from yarl import URL
>>> URL("http://localhost:8200")
URL('http://localhost:8200')
>>> URL("http://10.0.0.1:8200")
URL('http://10.0.0.1:8200')
$ pip freeze
idna==3.10
multidict==6.1.0
propcache==0.2.0
typing_extensions==4.12.2
yarl==1.13.0

xrmx avatar Oct 18 '24 07:10 xrmx

It's because the _host_validate is not called when you instantiate URL. See the regex actually breaking the format ip:port https://github.com/aio-libs/yarl/blob/v1.13.0/yarl/_url.py#L52

thetintin1000 avatar Oct 18 '24 09:10 thetintin1000

@thetintin1000 does it work if you bump aiohttp to 3.10.7?

xrmx avatar Oct 21 '24 07:10 xrmx