Linux

矩陣突觸 URL 預覽失敗 - netaddr.core.AddrFormatError

  • January 28, 2021

平台:Debian 9

矩陣/突觸版本:0.22.1-1

我首先安裝了必要的依賴項:

$ pip install lxml $ 點安裝netaddr

$ pip install twisted $ sudo apt install libxslt1-dev

然後我編輯了 /etc/matrix-synapse/homeserver.yaml 以便:

url_preview_enabled: true

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
- ‘209.58.160.224/32’
- ‘fc00::/7’

由於我的伺服器只有一個外部 IP 並且沒有內部子網,我認為這樣就可以了。

然後 Synapse 服務不斷重新啟動並產生此錯誤:

Sep 30 01:44:12 hostname python[29155]:     config["url_preview_ip_range_blacklist"]
Sep 30 01:44:12 hostname python[29155]:   File "/usr/lib/python2.7/dist-packages/netaddr/ip/sets.py", line 121, in __init__
Sep 30 01:44:12 hostname python[29155]:     for cidr in cidr_merge(mergeable):
Sep 30 01:44:12 hostname python[29155]:   File "/usr/lib/python2.7/dist-packages/netaddr/ip/__init__.py", line 1549, in cidr_merge
Sep 30 01:44:12 hostname python[29155]:     cidr = IPNetwork(ip)
Sep 30 01:44:12 hostname python[29155]:   File "/usr/lib/python2.7/dist-packages/netaddr/ip/__init__.py", line 933, in __init__
Sep 30 01:44:12 hostname python[29155]:     raise AddrFormatError('invalid IPNetwork %s' % addr)
Sep 30 01:44:12 hostname python[29155]: netaddr.core.AddrFormatError: <exception str() failed>
Sep 30 01:44:12 hostname systemd[1]: matrix-synapse.service: Main process exited, code=exited, status=1/FAILURE

我也嘗試了這些,但它們都產生了相同的錯誤:

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
- ‘209.58.160.224/32’
- ‘fc00::/7’

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
- ‘209.58.160.224/32’
#- ‘fc00::/7’

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
#- ‘209.58.160.224/32’
#- ‘fc00::/7’

更多配置失敗並出現相同錯誤:

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
# - ‘209.58.160.224/32’
# - ‘fc00::/7’

url_preview_ip_range_blacklist:
- ‘127.0.0.0'
# - ‘209.58.160.224/32’
# - ‘fc00::/7’

url_preview_ip_range_blacklist:
- ‘127.0.0.0/8'
- ‘209.58.160.224’
# - ‘fc00::/7’

最終解決方案是按照 Max 的建議更改引號:

這行得通,最終的語法是:

url_preview_enabled: true

url_preview_ip_range_blacklist:
- '127.0.0.0/8'
- '209.58.160.224/32'
- 'fc00::/7'

您的某些引號字元不是正常字元,而是“勾號”字元:vs'導致解析失敗。

引用自:https://serverfault.com/questions/876239