linux Linux nmcli unable to connect to password protected home WiFi
Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    3 weeks ago 100%

    Is your keyboard layout set correctly?

    I would suppose so, cause I used nmcli d WiFi connect SSID password PASSWORD, and the PASSWORD is displayed correctly.

    Does the SSID or password have a , or weird character?

    My password is alphanumeric, so that shouldn't be the issue. My SSID is alphanumeric + (), but I don't think that's the issue either cause I cannot connect to my password protected hotspot that is only alphanumeric.

    3
  • linux
    Linux 0WN3D 3 weeks ago 85%
    nmcli unable to connect to password protected home WiFi

    Hey, I am trying to connect to my home WiFi using nmcli but can't seem to connect. The error is ``` Error: Connection activation failed: (7) Secrets were required, but not provided. ``` The journal logs are at the bottom. Some context: * I am using arch linux ARM on a raspberry pi 4 * I am able to connect to non-password protected networks (I created one by using a hotspot on my phone). Once I set a password for the hotspot, I am unable to connect to the same network * I've tried the solutions in https://wiki.archlinux.org/title/NetworkManager#Secrets_were_required.2C_but_not_provided, but no success * Previously, I was using `netctl/netctl-auto` and it worked for my use case for a while. But one day, it cannot connect so I can't ssh into my pi for a few days. I got frustrated and uninstalled it and installed `nmcli` which I am more familiar with. But now I can't seem to connect to a password protected network, so looking back, maybe it wasn't netctl that was the root cause of the issue. ::: spoiler logs ``` Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:03:03 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:03:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:03:01 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:03:01 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:03:01 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:03:01 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:02:20 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:02:19 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:02:18 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:02:18 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:02:18 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:02:18 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:01:51 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:01:50 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:01:50 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:01:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:01:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:01:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:01:31 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:01:30 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:01:29 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:01:29 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:01:29 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:01:29 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:01:17 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:01:16 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:01:15 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:01:15 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:01:15 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:01:15 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:01:08 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:01:06 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:01:06 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:01:06 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:01:06 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:01:06 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:01:02 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:01:00 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:01:00 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:01:00 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:00:59 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:00:59 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:00:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:00:53 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:00:53 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:00:53 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:00:53 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:00:53 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:00:49 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:00:47 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:00:47 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:00:47 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:00:47 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:00:47 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:00:44 alarmpi wpa_supplicant[643]: wlan0: Reject scan trigger since one is already pending Aug 19 06:00:44 alarmpi NetworkManager[435]: <info> [1724018444.4181] device (p2p-dev-wlan0): supplicant management interface state: scanning -> inactive Aug 19 06:00:44 alarmpi NetworkManager[435]: <info> [1724018444.4179] device (wlan0): supplicant interface state: scanning -> inactive Aug 19 06:00:44 alarmpi wpa_supplicant[643]: wlan0: Removed BSSID 18:82:8c:07:ef:44 from ignore list (clear) Aug 19 06:00:43 alarmpi NetworkManager[435]: <info> [1724018443.7438] device (wlan0): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:43 alarmpi NetworkManager[435]: <warn> [1724018443.7420] device (wlan0): Activation: failed for connection 'MyWIFI99' Aug 19 06:00:43 alarmpi NetworkManager[435]: <info> [1724018443.7405] manager: NetworkManager state is now DISCONNECTED Aug 19 06:00:43 alarmpi NetworkManager[435]: <info> [1724018443.7390] device (wlan0): state change: need-auth -> failed (reason 'no-secrets', sys-iface-state: 'managed') Aug 19 06:00:43 alarmpi NetworkManager[435]: <warn> [1724018443.7389] device (wlan0): no secrets: No agents were available for this request. Aug 19 06:00:43 alarmpi NetworkManager[435]: <warn> [1724018443.7373] device (wlan0): Activation: (wifi) asking for new secrets Aug 19 06:00:43 alarmpi NetworkManager[435]: <info> [1724018443.7357] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:43 alarmpi NetworkManager[435]: <warn> [1724018443.7355] device (wlan0): Activation: (wifi) association took too long Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:00:40 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:00:38 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:00:38 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:00:38 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:00:38 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:00:38 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:00:34 alarmpi NetworkManager[435]: <info> [1724018434.3423] device (p2p-dev-wlan0): supplicant management interface state: disconnected -> scanning Aug 19 06:00:34 alarmpi NetworkManager[435]: <info> [1724018434.3422] device (wlan0): supplicant interface state: disconnected -> scanning Aug 19 06:00:34 alarmpi NetworkManager[435]: <info> [1724018434.2461] device (p2p-dev-wlan0): supplicant management interface state: associated -> disconnected Aug 19 06:00:34 alarmpi NetworkManager[435]: <info> [1724018434.2459] device (wlan0): supplicant interface state: associated -> disconnected Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="MyWIFI99" auth_failures=1 duration=10 reason=CONN_FAILED Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: BSSID 18:82:8c:07:ef:44 ignore list count incremented to 2, ignoring for 10 seconds Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-DISCONNECTED bssid=18:82:8c:07:ef:44 reason=3 locally_generated=1 Aug 19 06:00:34 alarmpi wpa_supplicant[643]: nl80211: send_event_marker failed: Source based routing not supported Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: Added BSSID 18:82:8c:07:ef:44 into ignore list, ignoring for 10 seconds Aug 19 06:00:34 alarmpi wpa_supplicant[643]: wlan0: Authentication with 18:82:8c:07:ef:44 timed out. Aug 19 06:00:24 alarmpi NetworkManager[435]: <info> [1724018424.2355] device (p2p-dev-wlan0): supplicant management interface state: associating -> associated Aug 19 06:00:24 alarmpi NetworkManager[435]: <info> [1724018424.2354] device (wlan0): supplicant interface state: associating -> associated Aug 19 06:00:24 alarmpi wpa_supplicant[643]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 Aug 19 06:00:24 alarmpi wpa_supplicant[643]: wlan0: Associated with 18:82:8c:07:ef:44 Aug 19 06:00:24 alarmpi systemd-networkd[306]: wlan0: Connected WiFi access point: MyWIFI99 (18:82:8c:07:ef:44) Aug 19 06:00:24 alarmpi NetworkManager[435]: <info> [1724018424.1339] device (p2p-dev-wlan0): supplicant management interface state: scanning -> associating Aug 19 06:00:24 alarmpi NetworkManager[435]: <info> [1724018424.1339] device (wlan0): supplicant interface state: scanning -> associating Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 06:00:24 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 06:00:24 alarmpi wpa_supplicant[643]: wlan0: Trying to associate with SSID 'MyWIFI99' Aug 19 06:00:22 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 06:00:22 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 06:00:22 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 06:00:22 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 06:00:22 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0909] device (p2p-dev-wlan0): supplicant management interface state: inactive -> scanning Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0908] device (wlan0): supplicant interface state: inactive -> scanning Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0557] Config: added 'psk' value '<hidden>' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0556] Config: added 'auth_alg' value 'OPEN' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0556] Config: added 'key_mgmt' value 'WPA-PSK WPA-PSK-SHA256 FT-PSK' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0556] Config: added 'bgscan' value 'simple:30:-70:86400' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0555] Config: added 'scan_ssid' value '1' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0555] Config: added 'ssid' value 'MyWIFI99' Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0554] device (wlan0): Activation: (wifi) connection 'MyWIFI99' has security, and secrets exist. No new secrets needed. Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0547] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0539] device (wlan0): state change: need-auth -> prepare (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0504] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0503] device (wlan0): Activation: (wifi) access point 'MyWIFI99' has security, but secrets are required. Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0496] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0487] manager: NetworkManager state is now CONNECTING Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0472] device (wlan0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed') Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0462] audit: op="connection-add-activate" uuid="68b7ad1d-29b3-402d-b925-5cbdc0bb07cc" name="MyWIFI99" pid=799 uid=1001 result="success" Aug 19 06:00:18 alarmpi NetworkManager[435]: <info> [1724018418.0453] device (wlan0): Activation: starting connection 'MyWIFI99' (68b7ad1d-29b3-402d-b925-5cbdc0bb07cc) Aug 19 06:00:01 alarmpi NetworkManager[435]: <info> [1724018401.4961] audit: op="connection-delete" uuid="eed97363-aa98-4d50-abab-4826666ca0fc" name="MyWIFI99" pid=784 uid=1001 result="success" Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 05:59:43 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 05:59:42 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 05:59:41 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 05:59:41 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 05:59:41 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 05:59:41 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 Aug 19 05:59:14 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd090 fail, reason -52 Aug 19 05:59:13 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02e fail, reason -52 Aug 19 05:59:12 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd02a fail, reason -52 Aug 19 05:59:12 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd026 fail, reason -52 Aug 19 05:59:12 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52 Aug 19 05:59:12 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0x100e fail, reason -52 Aug 19 05:58:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a5 fail, reason -52 Aug 19 05:58:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd0a1 fail, reason -52 Aug 19 05:58:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd09d fail, reason -52 Aug 19 05:58:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd099 fail, reason -52 Aug 19 05:58:55 alarmpi kernel: brcmfmac: brcmf_set_channel: set chanspec 0xd095 fail, reason -52 ``` :::

    5
    4
    "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPR
    General Programming Discussion 0WN3D 7 months ago 75%
    Recommendations on architecture for game AI tournament

    I'm planning on creating an AI tournament as a project to test out some of the potential AI performance in a game, _eg_ tic-tac-toe. I'd like the AI to know the full history of a game instead of the instantaneous game-state because I might want some AI that use the historical data, _eg_ AI that always put in the opposite cell of it's previous move if possible. The question I am wondering is, what is the best way to setup the tournament. I have a few options in my headspace: 1. Write everything in Rust (since I also am semi-interested in getting experience with the language) 2. Write everything in Python 3. Write the AI's in anything I want, but interact using stdin/stdout. Connect the AI using some shell script. There are a few nice things I want to have: 1. able to run AI ad hoc against each other, or easily modify the tourney. _ie_ I might want to add a new AI that runs against each of the previous AI instead of having the re-run the whole tourney * Rust would require a re-compile of the tourney code each time which may not be convenient * Options 2 and 3 would be much more convenient since it wouldn't require a full compilation and I can easily write a throwaway script 2. be able to run it in a somewhat performant way since I might want to simulate many rounds * Rust AI would be fast, but to avoid the issue in (1), I might go with solution 3 with the underlying AI being in Rust. But I'm not sure how significant the speed of piping IO between programs compare to if I had wrote everything as a Python program Any advice on this would be great, cause there might be some options that I might have omitted.

    4
    1
    asklemmy
    Asklemmy 0WN3D 8 months ago 86%
    Best way to get recommended videos

    I know there was quite a bit of controversy surrounding YouTube's recommendation algorithms, but I can't seem to find a better alternative. What are the ways y'all find videos that are of interest? I know we could use RSS and subscribe to our desired channels and get a better experience than YT's own subscription system, but what about channel/video discovery, those that you've never seen before? Is there a better way to find a video that might be interesting to you without kneeling before the almighty algorithm? Half of the recommended page on YT seems irrelevant to me, but I can't seem to find a better alternative.

    17
    7
    godot
    Godot 0WN3D 8 months ago 93%
    Quick advise on multiplayer deck builder

    Hey, I am planning on building a co-op multi-player deck builder as a side project, nothing fancy or grand of sorts. I'm kinda new to this Godot thing, but I kinda get the gist of it. Was always interested in it. I have prior experience with Game Maker and Unity, so picking up the basics was rather simple, given that I also do programming as a job. So don't simply dismiss this as too ambitious a project to start with when learning Godot. I just want to ask it out there, are there any advise on how I should structure the code or any advise in general? Just want to be prepared for issues in the future and plan for it. Basically, my initial idea of the game is think of multiplayer Slay the Spire. But I want a more elaborate upgrade system to the cards, closer to Wild Frost. For now, my head space for the design is to have: * Card details, _ie_ names + descriptions + image are resources since they are data that are "loaded in". * Actual cards that exists throughout the run would be actual nodes, with modifiers as child nodes + Multiplayer spawners to syncrhonise them. Base cards will pull details from the resource and have an empty modifier * I previously tried to build it using Multiplayer Synchronizer, but then suddenly realized I can only sync simple properties. It didn't let me create a custom node and synchronize it. Then I had to resort to some ID system for the object which became rather messy. * Based on my current testing, Multiplayer Spawner seems to do its job better. * Should I use a "modifier node" + children to indicate the list of effects, or an array variable? I'm not too sure when to use the node to organize data vs using an array variable * The actual cards are stored as a global node, which would be moved to the "playfield deck node" during the gameplay portion Lemme know if there is some obvious flaw in my approach or if there's a better way to do things. Or if such a project may be too ambitious with the current multiplayer library for Godot. Especially the multiplayer aspects, since there is not "a lot" of tutorials on it, I feel like there's a few pitfalls that is waiting for me.

    13
    1
    programming General Programming Discussion Help with API design for price pegging with JWT
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    Or, maybe just tell them the JWT they’ve got is expired, and ask them yes or no if they want the new (current) price instead, and update it transparently if they say yes.

    Based on this, it seems like you're suggesting to move the logic closer to the frontend and leave the auto-refetching logic out of the backend?

    The more I look at the responses, the more I feel this is a front-end problem to be solved rather than the backend's.

    1
  • programming General Programming Discussion Help with API design for price pegging with JWT
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    I think the idea was that if they managed to get the private key, we have away bigger problems on our hands than them submitting fraudulent orders. Even with server-side tokens, the same could happen if someone get access to your machine.

    1
  • programming General Programming Discussion Help with API design for price pegging with JWT
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    Actually, we are controlling both ends. But the issue is that frontend have rather limited bandwidth most of the time (sadly the truth is that despite that your own team wants to make things clean, other teams may not have the same stance).

    1
  • programming General Programming Discussion Help with API design for price pegging with JWT
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    I think the idea was that as long as it is within 5 min, our service can be certain that the price shouldn't change and thus we can save the computation cost of having to compute the price.

    It also is a user requirement, cause within that 5 min, even if the price is supposed to be changed, we will still use the price in the JWT.

    1
  • programming General Programming Discussion Help with API design for price pegging with JWT
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    What are the alternatives to a JWT. I know it is a bit bloated and we could just use the HS256 signature itself, but that doesn't really change the core problem of expiry vs auto-refetch

    1
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPR
    General Programming Discussion 0WN3D 8 months ago 100%
    Help with API design for price pegging with JWT

    I had this discussion in my workplace and wanted to share and get opinions from the folks here. (I suspect StackOverflow might not appreciate such open ended questions). Context: We have a microservice involved in pricing signalling to our users. We have an endpoint which have the following: * Input: an array of item ID's * Output: the expected final price of the given items. The item prices are quite volatile (and no, it is not crypto related), and is dependent on things like instantaneous supply-demand, promotions, _etc_. Since the prices change quite frequently, it became a requirement that we commit to the price that was shown to the user initially, up to a certain time period (_eg_ 5 min after the price was calculated). This improves the UX since the user will be charged as according to what they expected at the start. Currently, in our system, we achieve this via a JWT, which contains all the details in the request, the obligatory signature, and the expiry set to 5 min from the time it was generated. After generating this receipt, the FE can then call the endpoint with the JWT which does the actual payment processing using the params encoded in the token. This way, we know that the params + the total cost that is quoted in the JWT originates from our service since we verify that we signed it. And the system evolves once more. We see that in the system, there is this mechanism, that if the token is expired, we do not reject the request at the charging step. Instead, we call the price endpoint internally using the params provided, and check if the price is the same as in the expired JWT. If it is the same, we process it as normal despite the JWT being expired. This is where the contention lies. I believe that we should force the user to procure another non-expired JWT and removing this complex logic while others believe in the value of this improved UX where the user doesn't need to restart the whole flow again. What do y'all think? Which way would y'all architect the endpoint? Or is there something fundamentally wrong with our design (maybe JWT is not the best suited for this use case)?

    6
    12
    asklemmy Asklemmy Mosquito splinters
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    8 months ago 100%

    Oh, ticks are rare in my region, that's why I have no prior experience with them.

    I was thinking in the context of us slapping the mosquito would be equivalent to slamming a thumbtack into your skin which could increase the damage dealt and penetration depth.

    1
  • asklemmy
    Asklemmy 0WN3D 9 months ago 96%
    Mosquito splinters

    Just a random shower thought. Mosquito's proboscis is sharp enough to penetrate your skin. So when you smack it while it is in the process of drawing your blood, isn't there a chance of its proboscis being forcefully jammed into your skin, leading to some sort of "splinter"? Or does it somehow loses its stiffness the moment it feels the impact? I've never encountered nor heard of such occurrence in my lifetime of killing those buggers, but wondering if such a thing is even possible. If such could happen, I could only imagine the risk associated with having a piece of foreign organic matter being embed in the body

    61
    13
    archlinux Arch Linux [Solved] How to know why a package is being updated/installed
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    9 months ago 100%

    Oh, I didn't knew you can pass 2 is. I was depending on the tab completion from pacman, but I didn't see that it says you could specify i's

    1
  • archlinux Arch Linux [Solved] How to know why a package is being updated/installed
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    9 months ago 100%

    Ah, it worked. I thought Qi only works for packages that are already installed. Didn't knew it worked for things that are synced as a new dependency of a package

    1
  • archlinux
    Arch Linux 0WN3D 9 months ago 100%
    [Solved] How to know why a package is being updated/installed

    Hey, sometimes when I do `pacman -Syu`, I see some weird package being installed and I am curious which explicitly installed package is installing/updating it. How do I so with `pacman`? I know we can easily find out why an installed package is being installed, but what about before the package is being installed?

    26
    7
    linux Linux MPV dropping frames and audio
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    11 months ago 100%

    Tried the settings on the GitHub, doesn't seem to work, and it also made the stuttering worse

    opengl-pbo=yes
    opengl-early-flush=no.
    video-sync=display-resample
    

    ok, here you go

    https://pastebin.com/uPc5S1LU

    1
  • linux Linux MPV dropping frames and audio
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    11 months ago 100%

    Yea, it seems to be using 200% CPU. But I have vo=gpu though, so I'd thought the GPU would've taken some of the load.

    If I am strapped for CPU resources, how do I make it so that MPV buffer or something instead of dropping the audio when this happens? Cause it is strange the even though the visuals are acceptable, it is the audio that fails before the video

    1
  • linux
    Linux 0WN3D 11 months ago 100%
    MPV dropping frames and audio

    I've tried searching around and stuff but I couldn't find a working solution Background: I am running Arch Linux on a Raspberry Pi, mainly as a media player. When I run MPV, it seems to drop frames (1-2 per second). Visually, nothing looks wrong so I am fine with that. The issue is that after playing for some duration, the audio will just disappear. I would then need to pause the video for a while or seek backwards for the audio to come back (sometimes it just comes back on its own when I leave it playing too). I suspect it may be due to the dropped frames or maybe it's due to insufficient system resource. Could someone help suggest some config changes which may help with the issue? I am totally fine with the visual dropped frames, I just want to fix the audio issue. This is my config. ``` input-ipc-server=/tmp/mpvsocket ao=pipewire volume=120 demuxer-readahead-secs=3 cache=yes ```

    22
    6
    archlinux Arch Linux [Resolved] Missing audio with MPV + Wayland
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    are you running it from a tty on login

    Yea, directly on tty.

    I imagine these are two separate issues.

    I'd think they are related since mpv is working fine on Xwayland but not when I launch alacritty instead

    Can you dump your installed packages with pacman -Qe and post it here? I’ll compare it to mine.

    alacritty 0.12.2-1
    ani-cli 4.6-1
    archlinuxarm-keyring 20140119-2
    base 3-1
    base-devel 1-1
    bat 0.23.0-3
    cage 0.1.5-1
    dhcpcd 10.0.2-1
    dialog 1:1.3_20230209-1
    linux-rpi 6.1.54-1
    lobster 4.0.0-1
    man-db 2.11.2-1
    neovim 0.9.1-1
    net-tools 2.10-2
    netctl 1.28-2
    noto-fonts 1:23.9.1-1
    opendoas 6.8.2-1
    openssh 9.4p1-4
    pacman-contrib 1.9.1-1
    raspberrypi-bootloader 20230921-1
    raspberrypi-firmware 20230921-1
    ripgrep 13.0.0-3
    socat 1.7.4.4-1
    tmux 3.3_a-7
    vi 1:070224-6
    which 2.21-6
    wireless-regdb 2023.09.01-1
    wireless_tools 30.pre9-3
    wpa_supplicant 2:2.10-8
    xorg-xwayland 23.2.1-1
    
    1
  • archlinux Arch Linux [Resolved] Missing audio with MPV + Wayland
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    That shouldn't be the problem since I'm using pipewire and it is working in the Xwayland session. When I launch into alacritty, I also checked that pipewire + wireplumber were both active

    1
  • archlinux Arch Linux [Resolved] Missing audio with MPV + Wayland
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    I tried with cage + Xwayland and that works perfectly, so I highly doubt that is the issue. Maybe it is something to do with cage + alacritty that is causing it, but I'm not too well versed in the Wayland stuff to know if spawning a terminal application may somehow not support audio.

    1
  • archlinux
    Arch Linux 0WN3D 12 months ago 80%
    [Resolved] Missing audio with MPV + Wayland

    So I know my setup is really niche, but here goes nothing * I am using Arch Pi on Pi 4 * Installed `cage` as a lightweight Wayland compositor * Installed `mpv + wireplumber + pipewire` I am not quite sure how to use `cage` to launch a simple "Wayland session (if it even makes sense)", so that I can send MPV to that display. So I tried `cage -s alacritty :1`, and it does launch `alacritty` with it detecting that it is on `wayland`. But when I do `DISPLAY=:1 mpv ....`, the video runs, but there's no audio. Also there's no errors shown on `mpv` either. The other thing of note is that I tried `cage -s Xwayland :1` and the audio+video works perfectly. So in all: 1. How do I launch `cage` to spawn a simple Wayland session? Is this even possible? 2. How do I solve the audio issue on Wayland? EDIT: Thanks all for the help. After some investigation, I found out the `pipewire` somehow is not ran on startup of `alacritty`, but it did for `Xwayland`. I noticed that the first play of the video would be audio-less on `alacritty`, and subsequent ones are fine. It seems like the first run causes `pipewire` to be started and thus I wrongfully assumed that the daemon was running. Still strange nonetheless...

    9
    8
    python Python [Answered] Typehints for functions that have variable signatures
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    I think there's a spectrum here, and I'll clarify the stances.

    The spectrum ranges from "Data shouldn't cause the function to do (something wildly) different" to "It should be allowed, even to the point of variable returns"

    I think you stand on the former while I stand on the latter. Correct me if I'm wrong though, but that's the vibe I'm getting from the tone in your example.

    Data shouldn’t drive the program in this way.

    Suppose we have a function that calculates a price of an object. I feel it is agreeable for us to have compute_price(with_discount: bool), over compute_price_with_discount() + compute_price_without_discount()

    You’ve basically spelled:

    I feel your point your making in the example is a bit exaggerated. Again, coming back to my above example, I don't think we would construe it as compute_price('with_discount').

    Maybe this is bandwagoning, but one of the reason for my stance is that there are quite a few examples of variable returns.

    eg:

    • getattr may return a different type base on the key given
    • quite a few functions in numpy returns different things based on flags. SVD will return S if compute_uv=False and S,U,V otherwise
    2
  • python Python [Answered] Typehints for functions that have variable signatures
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    I thought about it, but it isn't as expressive as I wished.

    Meaning if I do

    a = foo(return_more=True)
    or
    a, b = foo(return_more=False)
    

    it doesn't catch these errors for me.

    In comparison, the other suggested solution does catch these.

    1
  • python Python [Answered] Typehints for functions that have variable signatures
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    yea, this is pretty close to what I'm looking for.

    The only missing piece is the ability to define the overload methods on the bool

    something like

    @overload
    def foo(return_more: True) -> (Data, Data)
    
    @overload
    def foo(return_more: False) -> Data
    

    But I don't think such constructs are possible? I know it is possible in Typescript to define the types using constants, but I don't suppose Python allows for this?

    EDIT: At first, when I tried the above, the typechecker said Literal[True] was not expected and I thought it was not possible. But after experimenting some, I figured out that it is actually possible. Added my solution to the OP

    Thanks for the tip!

    2
  • python Python [Answered] Typehints for functions that have variable signatures
    Jump
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebear0W
    0WN3D
    12 months ago 100%

    but from a practical perspective, let's say you retrieve an object and can either return a subset of its fields as your API. Doesn't it make sense to re-use the same function, but change what fields are returned?

    I'm specifically talking about the narrow use-case where your API returns either A or B of the fields, and won't extend it in the future

    The alternative is to either duplicate the function, or extract it out which seems a bit overkill if it is only 2 different type of functions.

    1
  • python
    Python 0WN3D 12 months ago 95%
    [Answered] Typehints for functions that have variable signatures

    I know what I am asking is rather niche, but it has been bugging me for quite a while. Suppose I have the following function: ``` python def foo(return_more: bool): .... if return_more: return data, more_data return data ``` You can imagine it is a function that may return more data if given a flag. How should I typehint this function? When I use the function in both ways ``` data = foo(False) data, more_data = foo(True) ``` either the first or the 2nd statement would say that the function cannot be assigned due to wrong size of return tuple. Is having variable signature an anti-pattern? Is Python's typehinting mechanism not powerful enough and thus I am forced to ignore this error? Edit: Thanks for all the suggestions. I was enlightened by [this suggestion](https://lemmy.cafe/comment/1984266) about the existence of `overload` and this solution fit my requirements perfectly ``` from typing import overload, Literal @overload def foo(return_more: Literal[False]) -> Data: ... @overload def foo(return_more: Literal[True]) -> tuple[Data, OtherData]: ... def foo(return_more: bool) -> Data | tuple[Data, OtherData]: .... if return_more: return data, more_data return data a = foo(False) a,b = foo(True) a,b = foo(False) # correctly identified as illegal ```

    22
    18