greghesp / ha-bambulab

A Home Assistant Integration for Bambu Lab Printers
971 stars 85 forks source link

[Bug] Failed to connect. #612

Closed FeiiiikLV closed 2 weeks ago

FeiiiikLV commented 2 weeks ago

Describe the bug

Trying to connect to Bambu Cloud. Changed the password in BambuLab to update to new password standards. Email removed for security. image

To Reproduce

Install Integration and try to activate it.

Expected Behaviour

I expected to login into Bambu Cloud and add printers with cloud connection

What device are you using?

P1P

Diagnostic Output

Can't, because the Integration isn't active yet.

Log Extracts

No response

Other Information

No response

damian-w commented 2 weeks ago

Same issue - reset my password and still no luck.

zhujunsan commented 2 weeks ago

Same here, I've got errors in logs:

image

image

Edited: My timezone is +8

marwiak commented 2 weeks ago

same for me

bscheutjens commented 2 weeks ago

I seem to have the same issue, my logging is being flooded with the same errors as @zhujunsan and the enity "Current stage" shows that my printer is offline. It started at 11:22 AM CEST. Although this might look like Bambu cloud issue, both Bambu Studio and Bamby Handy work perfectly fine.

I'm not sure if it is somehow related, but it started at the same time (to the minute) as I got a notification in Bambu Handy that a print was ready.

curlydingo commented 2 weeks ago

Same issue here too, but I haven't changed my password or reconfigured the integration lately.

I get a total of 4 different error messages repeating quite rapidly (every ~2 seconds, integration had been running for about 8 minutes at time of screenshot):

image

In the order they appear in that screenshot, the sources are as follows:

custom_components/bambu_lab/pybambu/bambu_client.py:266 custom_components/bambu_lab/pybambu/bambu_client.py:265 custom_components/bambu_lab/pybambu/bambu_client.py:401 custom_components/bambu_lab/pybambu/bambu_client.py:397

No other useful information in the errors as far as I can tell.

Edit: Debug log excerpt follows, IP removed but the rest is unchanged:

2024-10-21 21:52:56.588 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Connect: Attempting Connection to XXX.XXX.XXX.XXX 2024-10-21 21:52:57.400 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Starting listen loop 2024-10-21 21:52:57.405 INFO (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] On Connect: Connected to Broker 2024-10-21 21:52:57.405 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Loading slicer settings... 2024-10-21 21:52:57.405 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Loading slicer settings 2024-10-21 21:52:57.405 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Getting slicer settings from Bambu Cloud 2024-10-21 21:52:57.443 DEBUG (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Received error: 403 2024-10-21 21:52:57.443 ERROR (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] A listener loop thread exception occurred: 2024-10-21 21:52:57.443 ERROR (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] Exception. Type: <class 'ValueError'> Args: 403 2024-10-21 21:52:58.444 WARNING (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] On Disconnect: Disconnected from Broker: 0 2024-10-21 21:52:58.444 WARNING (P1S-Mqtt-67) [custom_components.bambu_lab.pybambu] _on_disconnect

Perhaps some sort of cloud auth/API change?

kurim commented 2 weeks ago

I have the same problem, thought i was blocked by API.

But after login through postman and manual check mqtt with mqttx everything is fine.

vaderag commented 2 weeks ago

I haven't had time to dive in to logs, but noticed that my printer isn't sending info to HA where as it was last week

systemerror-codenotfound commented 2 weeks ago

Same problem here, no data from the integration and all appear disconnected

Failed to connect when trying to configure it back Removed the printer and also removed the integration but it's not working and the credentials are 100% fine

Failed to connect. Check credentials.

robertklep commented 2 weeks ago

This also breaks local/LAN mode setups because it's trying to download something from Bambu Cloud, and failing:

2024-10-21 15:30:45.338 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Connect: Attempting Connection to 192.168.23.239
2024-10-21 15:30:46.076 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Starting listen loop
2024-10-21 15:30:46.079 INFO (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] On Connect: Connected to Broker
2024-10-21 15:30:46.079 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Loading slicer settings...
2024-10-21 15:30:46.079 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Loading slicer settings
2024-10-21 15:30:46.079 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Getting slicer settings from Bambu Cloud
2024-10-21 15:30:46.119 DEBUG (P1S-Mqtt-68) [custom_components.bambu_lab.pybambu] Received error: 403

I commented out the slicer settings updates that are causing this to get things working again for now (gist of pybambu/bambu_client.py)

Asakiro commented 2 weeks ago

Same issue here, Login to Cloud failed. Maybe it's Bambu ..

formatBCE commented 2 weeks ago

+1, same on North America, A1 here.

FWeinb commented 2 weeks ago

Just randomly stopped working for me too, was working fine yesterday evening. P1S, Lan Mode.

[Edit] Applying this patch to bambu_client.py

300,301c300,301
<         self.bambu_cloud = BambuCloud(region, email, username, auth_token)
<         self.slicer_settings = SlicerSettings(self)
---
>         # self.bambu_cloud = BambuCloud(region, email, username, auth_token)
>         # self.slicer_settings = SlicerSettings(self)
346c346
<         self.slicer_settings.update()
---
>         # self.slicer_settings.update()
487c487
<         self.slicer_settings.update()
---
>         # self.slicer_settings.update()

solves it, but you won't get filament infos anymore. Looks like logging into the bambu account is broken.

Offpiste84 commented 2 weeks ago

Is stopped working here on A1 in LAN mode.

feli0x commented 2 weeks ago

Just randomly stopped working for me too, was working fine yesterday evening. P1S, Lan Mode.

[Edit]

Applying this patch to bambu_client.py


300,301c300,301

<         self.bambu_cloud = BambuCloud(region, email, username, auth_token)

<         self.slicer_settings = SlicerSettings(self)

---

>         # self.bambu_cloud = BambuCloud(region, email, username, auth_token)

>         # self.slicer_settings = SlicerSettings(self)

346c346

<         self.slicer_settings.update()

---

>         # self.slicer_settings.update()

487c487

<         self.slicer_settings.update()

---

>         # self.slicer_settings.update()

solves it, but you won't get filament infos anymore. Looks like logging into the bambu account is broken.

This worked for me!

spawnrider commented 2 weeks ago

Same issue for me on my X1C.

andybali commented 2 weeks ago

same here

mkw1056 commented 2 weeks ago

Same here

kurim commented 2 weeks ago

Ok i have try to connect with python. The reason why it does not work is the cloudflare protection.

Response status: 403

Attention Required! | Cloudflare

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

Rootcause:

requests onyl can http 1.1 instead of http2

this may fix it:

        # Using httpx.Client with http2=True
        with httpx.Client(http2=True) as client:
            response = client.post(url, json=data, timeout=10)

        if not response.is_success:
            LOGGER.debug(f"Received error: {response.status_code}")
            raise ValueError(f"Error: {response.status_code} - {response.text}")

        return response.json()['accessToken']

not tested....

but tbh. py is not my world xD

@AdrianGarside maybe you can help here to solve it

Menthe11 commented 2 weeks ago

That only checks out for the cloud account and not LAN only mode, right?

kurim commented 2 weeks ago

Yes the lan mode should work correct if u follow this: https://github.com/greghesp/ha-bambulab/issues/607

bscheutjens commented 2 weeks ago

not tested....

but tbh. py is not my world xD

@AdrianGarside maybe you can help here to solve it

I can test that code if you want. The only thing is that I'm completely new to this integration (got my printer last Friday), so I have no idea where to change this code. So if that is something you can tell me, I can change the code and test.

kurim commented 2 weeks ago

I have try it here: filebrowser: /homeassistant/custom_components/bambu_lab/pybambu/bambu_cloud.py

But i'm not sure if this works if i just change it and restart hass

nagi603 commented 2 weeks ago

The DDoS of holiday sale probably also nuked their backend API. It started right about the time people started reporting issues.

Menthe11 commented 2 weeks ago

Just randomly stopped working for me too, was working fine yesterday evening. P1S, Lan Mode.

[Edit]

Applying this patch to bambu_client.py


300,301c300,301

<         self.bambu_cloud = BambuCloud(region, email, username, auth_token)

<         self.slicer_settings = SlicerSettings(self)

---

>         # self.bambu_cloud = BambuCloud(region, email, username, auth_token)

>         # self.slicer_settings = SlicerSettings(self)

346c346

<         self.slicer_settings.update()

---

>         # self.slicer_settings.update()

487c487

<         self.slicer_settings.update()

---

>         # self.slicer_settings.update()

solves it, but you won't get filament infos anymore. Looks like logging into the bambu account is broken.

This worked for me!

Works for me too, apart from the AMS. All slots are empty.

bscheutjens commented 2 weeks ago

I have try it here: filebrowser: /homeassistant/custom_components/bambu_lab/pybambu/bambu_cloud.py

But i'm not sure if this works if i just change it and restart hass

I think I changed it in the correct location and restarted HASS. I don't get any (additional) error in the logging, so the change at least doesn't give any compile/run error. However, it does not solve the issue. I'm still getting the same errors as before and I get no data from my printer.

elemakil commented 2 weeks ago

@bscheutjens @kurim

You'd have to replace every use of the requests library targeting the BambuLab API by calls using the httpx API. Or at least, you'd need to replace more than just the login call used to retrieve the accessToken. There seem to be five API calls, all located in bambu_cloud.py.

I did not modify bambu_cloud.py yet because as far as I can tell, my HomeAssistant does not have httpx installed.

TheDuffman85 commented 2 weeks ago

You also need to add httpx as a requirement to the manifest. I can confirm that this fix is working. I'll create a pull request.

kurim commented 2 weeks ago

Initial to see i create it out off homeassistant to see the request response, after searching for a solution for cloudflare and python I run into httpx (pip install httpx + pip install httpx[http2]).

It seems httpx is already installed: image

so this could work

bscheutjens commented 2 weeks ago

I copied the changes from @TheDuffman85 into my local files, restarted HASS and the integration works again. Thanks @TheDuffman85

kurim commented 2 weeks ago

Yes, I also can confirm that it works, big shoutout to @TheDuffman85 !

What still need to fix is the mqtt.

Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x7f75109ad0>,) inside the event loop by custom integration 'bambu_lab' at custom_components/bambu_lab/pybambu/bambu_client.py, line 519:
self.client.tls_set(tls_version=ssl.PROTOCOL_TLS, cert_reqs=ssl.CERT_NONE) (offender: /usr/local/lib/python3.12/site-packages/paho/mqtt/client.py, line 806: context.load_default_certs())
miketarg commented 2 weeks ago

Will this be patched as I have this issue too X1C

hubertron commented 2 weeks ago

Lan mode also fails

pilo1337 commented 2 weeks ago

@TheDuffman85 I changed the manifest.json and bambu_cloud.py manual from your pull request and your fix works Like a charm! Very good Job!!

Hope the PR gets merged soon, you deserved it :)

systemerror-codenotfound commented 2 weeks ago

Same here after changing the files restarted HASS and the integration works . Thanks @TheDuffman85

bumpabuilt-git commented 2 weeks ago

I edited my files with @TheDuffman85 changes and it's back up and running! We have 71 printers to monitor so we were lost without this!

Jarod2801 commented 2 weeks ago

Works all fine again after editing the 2 files suggested by @TheDuffman85 . Includung AMS.

Great work! Thanks!

damian-w commented 2 weeks ago

Have also updated my files according to @TheDuffman85 and it's working great.

JMT000 commented 2 weeks ago

You also need to add httpx as a requirement to the manifest. I can confirm that this fix is working. I'll create a pull request.

Can confirm working. Thank you!

AdrianGarside commented 2 weeks ago

New dev release with this fix: https://github.com/greghesp/ha-bambulab/releases/tag/v2.0.23-dev3

Please test and let me know if you see any issues.

AdrianGarside commented 2 weeks ago

I edited my files with @TheDuffman85 changes and it's back up and running! We have 71 printers to monitor so we were lost without this!

71!!! I'm impressed HA / this integration can scale that well.

curlydingo commented 2 weeks ago

New dev release with this fix: https://github.com/greghesp/ha-bambulab/releases/tag/v2.0.23-dev3

Please test and let me know if you see any issues.

Looks good to me!

Heads up for others moving from the standard release: the “image” entity of the printer camera is no longer provided; instead there is a new “camera” entity. If you also use the Obico spaghetti detection automation I don’t believe the included blueprints will work for you any more.

FeiiiikLV commented 2 weeks ago

I edited my files with @TheDuffman85 changes and it's back up and running! We have 71 printers to monitor so we were lost without this!

Hey, any chance you could help me set up a dashboard, currently trying to create a dashboard with my 45 printers to display current statuses and help me navigate all the printers.

FeiiiikLV commented 2 weeks ago

New dev release with this fix: https://github.com/greghesp/ha-bambulab/releases/tag/v2.0.23-dev3

Please test and let me know if you see any issues.

This fixed the issue, now I can add all the devices. The only thing I notice is that when adding the devices quickly it gives an error that the credentials are wrong. Maybe something to do with downloading data... Usually happens when I add 2 or 3 printers really fast.

bscheutjens commented 2 weeks ago

New dev release with this fix: https://github.com/greghesp/ha-bambulab/releases/tag/v2.0.23-dev3

Please test and let me know if you see any issues.

Seems to be working for me, thanks

Menthe11 commented 2 weeks ago

Can confirm, works in LAN only mode. Thanks @TheDuffman85

Jerome1998 commented 2 weeks ago

After updating to dev branch everything works fine, thanks 👍

Lippi08 commented 2 weeks ago

Funktioniert wieder einwandfrei nach dem Bearbeiten der 2 Dateien vorgeschlagen von https://github.com/TheDuffman85 Einschließlich AMS.

Tolle Arbeit! Vielen Danke!

cosmith71 commented 2 weeks ago

Possibly dumb question because I'm possibly dumb, but how do I update to the dev branch?

TheDuffman85 commented 2 weeks ago

Simplest way is to install v2.0.23-dev3 using HACS. But this version is currently only running with HA 2024.10. PR #616 will make it compatible with older HA versions as well.

cosmith71 commented 2 weeks ago

Simplest way is to install v2.0.23-dev3 using HACS. But this version is currently only running with HA 2024.10. PR #616 will make it compatible with older HA versions as well.

That worked. Thanks!

It seems to be working as intended again.