Title: [Bug] can.detect_available_configs("socketcan") fails with KeyError: "link_type" · Issue #1598 · hardbyte/python-can · GitHub
Open Graph Title: [Bug] can.detect_available_configs("socketcan") fails with KeyError: "link_type" · Issue #1598 · hardbyte/python-can
X Title: [Bug] can.detect_available_configs("socketcan") fails with KeyError: "link_type" · Issue #1598 · hardbyte/python-can
Description: Describe the bug Hi, we had here a docker container with host network setting enabled (Ubuntu 22.04 inside and outside). it creates vcan interfaces. when I create a small file like import can can.detect_available_configs("socketcan") and...
Open Graph Description: Describe the bug Hi, we had here a docker container with host network setting enabled (Ubuntu 22.04 inside and outside). it creates vcan interfaces. when I create a small file like import can can.d...
X Description: Describe the bug Hi, we had here a docker container with host network setting enabled (Ubuntu 22.04 inside and outside). it creates vcan interfaces. when I create a small file like import can can.d...
Opengraph URL: https://github.com/hardbyte/python-can/issues/1598
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug] can.detect_available_configs(\"socketcan\") fails with KeyError: \"link_type\"","articleBody":"### Describe the bug\r\n\r\nHi, we had here a docker container with host network setting enabled (Ubuntu 22.04 inside and outside). it creates vcan interfaces.\r\n\r\nwhen I create a small file like\r\n\r\n```python\r\nimport can\r\n\r\ncan.detect_available_configs(\"socketcan\")\r\n```\r\nand run it via python, i got the following error:\r\n\r\nTraceback (most recent call last):\r\n File \"tmp.py\", line 3, in \u003cmodule\u003e\r\n can.detect_available_configs(\"socketcan\")\r\n File \"/usr/local/lib/python3.10/dist-packages/can/interface.py\", line 186, in detect_available_configs\r\n bus_class._detect_available_configs() # pylint: disable=protected-access\r\n File \"/usr/local/lib/python3.10/dist-packages/can/interfaces/socketcan/socketcan.py\", line 878, in _detect_available_configs\r\n for channel in find_available_interfaces()\r\n File \"/usr/local/lib/python3.10/dist-packages/can/interfaces/socketcan/utils.py\", line 69, in find_available_interfaces\r\n interfaces = [i[\"ifname\"] for i in output_json if i[\"link_type\"] == \"can\"]\r\n File \"/usr/local/lib/python3.10/dist-packages/can/interfaces/socketcan/utils.py\", line 69, in \u003clistcomp\u003e\r\n interfaces = [i[\"ifname\"] for i in output_json if i[\"link_type\"] == \"can\"]\r\nKeyError: 'link_type'\r\n\r\nThe problem here is that the output of\r\n\r\n```bash\r\nip -json link list up\r\n```\r\nresults in\r\n\r\n```json\r\n[\r\n {\r\n \"ifindex\": 1,\r\n \"ifname\": \"lo\",\r\n \"flags\": [\r\n \"LOOPBACK\",\r\n \"UP\",\r\n \"LOWER_UP\"\r\n ],\r\n \"mtu\": 65536,\r\n \"qdisc\": \"noqueue\",\r\n \"operstate\": \"UNKNOWN\",\r\n \"linkmode\": \"DEFAULT\",\r\n \"group\": \"default\",\r\n \"txqlen\": 1000,\r\n \"link_type\": \"loopback\",\r\n \"address\": \"00:00:00:00:00:00\",\r\n \"broadcast\": \"00:00:00:00:00:00\"\r\n },\r\n {},\r\n {\r\n \"ifindex\": 5,\r\n \"ifname\": \"docker0\",\r\n \"flags\": [\r\n \"NO-CARRIER\",\r\n \"BROADCAST\",\r\n \"MULTICAST\",\r\n \"UP\"\r\n ],\r\n \"mtu\": 1500,\r\n \"qdisc\": \"noqueue\",\r\n \"operstate\": \"DOWN\",\r\n \"linkmode\": \"DEFAULT\",\r\n \"group\": \"default\",\r\n \"link_type\": \"ether\",\r\n \"address\": \"02:42:48:75:80:6b\",\r\n \"broadcast\": \"ff:ff:ff:ff:ff:ff\"\r\n },\r\n...\r\n```\r\n\r\nso especially there is one empty json object in between the other devices. This is the problematic one. So to fix it, in\r\n\r\npython-can/can/interfaces/socketcan/utils.py\r\n\r\nat line 69 one need to check if i is empty or maybe even better if i contains \"link_type\".\r\n\r\n### To Reproduce\r\n\r\nI found no way to easy reproduce this one without our docker container at the moment, it can be simulated if instead of the \"ip -json link list up\" call (python-can/can/interfaces/socketcan/utils.py row 52) in the code some json is read (or python hardcoded list) that contains an empty dict / object. \r\n\r\n### Expected behavior\r\n\r\nThe python script given above should run without errors :-).\r\n\r\n\r\n### Additional context\r\n\r\nOS and version: Ubuntu 22.04 inside docker Ubuntu 22.04\r\nPython version: 3.10.6\r\npython-can version: 4.2.1\r\npython-can interface/s (if applicable): vcan\r\n\r\n\u003cdetails\u003e\u003csummary\u003eTraceback and logs\u003c/summary\u003e\r\n\u003c!-- Has to be followed by an empty line! --\u003e\r\n\r\n\u003c!-- More details such as a minimal script to demonstrate the bug, relevant logs and any tracebacks go here. --\u003e\r\n\r\n\u003c!-- Code examples can be included: --\u003e\r\n\u003c/details\u003e\r\n","author":{"url":"https://github.com/DanielBrandes-FlyNow","@type":"Person","name":"DanielBrandes-FlyNow"},"datePublished":"2023-05-17T11:21:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1598/python-can/issues/1598"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:66d78333-6c15-22bf-d5c3-13e50d666267 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7D0:43F78:D630A28:12189206:6A5F5247 |
| html-safe-nonce | bf1e4bb67b27b5c17321044ab24e490dc13e72fedea4c5813993402c4f23d84a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0QwOjQzRjc4OkQ2MzBBMjg6MTIxODkyMDY6NkE1RjUyNDciLCJ2aXNpdG9yX2lkIjoiNDM1MTY2NjY0NzExNzgxMjI5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a123a590ade6f592495e4d5068bd9c3433a212b27a978dc9201beeb6b6ad3b0 |
| hovercard-subject-tag | issue:1713675907 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hardbyte/python-can/1598/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6e6663a1be7abc2fef2fe0735bddd3e08210313d0e69492a9e45842face947af/hardbyte/python-can/issues/1598 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6e6663a1be7abc2fef2fe0735bddd3e08210313d0e69492a9e45842face947af/hardbyte/python-can/issues/1598 |
| og:image:alt | Describe the bug Hi, we had here a docker container with host network setting enabled (Ubuntu 22.04 inside and outside). it creates vcan interfaces. when I create a small file like import can can.d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielBrandes-FlyNow |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9a0797c11799dbfd7df57fa3de31c7ea3a4c4bd055eb1a0427a5cde1d4d7ba3f |
| turbo-cache-control | no-preview |
| go-import | github.com/hardbyte/python-can git https://github.com/hardbyte/python-can.git |
| octolytics-dimension-user_id | 855189 |
| octolytics-dimension-user_login | hardbyte |
| octolytics-dimension-repository_id | 69090889 |
| octolytics-dimension-repository_nwo | hardbyte/python-can |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 69090889 |
| octolytics-dimension-repository_network_root_nwo | hardbyte/python-can |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b099d96da147aea31036cd16b2fba0083a6defe4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width