Skip to content

Fix P100 error getting conn closed when trying default login after login failure #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented Jan 23, 2024

No description provided.

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e233e37) 87.13% compared to head (263e294) 87.15%.

Files Patch % Lines
kasa/aestransport.py 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #690      +/-   ##
==========================================
+ Coverage   87.13%   87.15%   +0.01%     
==========================================
  Files          39       39              
  Lines        3544     3549       +5     
  Branches      899      900       +1     
==========================================
+ Hits         3088     3093       +5     
  Misses        377      377              
  Partials       79       79              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -180,19 +180,28 @@ async def perform_login(self):
"""Login to the device."""
try:
await self.try_login(self._login_params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does fix the issue but we do handshake 2x now on discovery

DEBUG:kasa.aestransport:Generating keypair
DEBUG:kasa.aestransport:Handshake params: {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZbufuct/b1qSTmUpaLVApGIEMaspNgu1cwTJF4LN0XVXtIoPk+xx0rruNDOTOpVkLpT2Rw/UVyxt63fMktC03Y/1x+BfVfLbDXYTmlFE5+180KP0lwAN8uipqAaHHkEPR0mw1xoiyndZTu9O2CSexdvQeQh8/uNiTYiJZxJ9rTwIDAQAB\n-----END PUBLIC KEY-----\n'}
DEBUG:kasa.aestransport:Request {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZbufuct/b1qSTmUpaLVApGIEMaspNgu1cwTJF4LN0XVXtIoPk+xx0rruNDOTOpVkLpT2Rw/UVyxt63fMktC03Y/1x+BfVfLbDXYTmlFE5+180KP0lwAN8uipqAaHHkEPR0mw1xoiyndZTu9O2CSexdvQeQh8/uNiTYiJZxJ9rTwIDAQAB\n-----END PUBLIC KEY-----\n'}}
DEBUG:kasa.aestransport:Device responded with: {'error_code': 0, 'result': {'key': 'cVxMCtYukLw31nzEr5L/ytLSFjR33CED9KAkwAh6fJFfiAu3LvyifLFx3dWCQUQfLEDrZSjvH53ru0MUtyvWiSqn8JNuliRJ8MHxfe477ksarKWyLkdhxFoCYZ91AMhIpGQ2WofrGxDOvgpXWIbTOJLLirK0JP6CqacZP4cKdAo='}}
DEBUG:kasa.aestransport:Handshake with 192.168.107.47 complete
DEBUG:kasa.aestransport:Will perform handshaking...
DEBUG:kasa.aestransport:Generating keypair
DEBUG:kasa.aestransport:Handshake params: {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDal8slelSWpAjM+TXxqVVul2TWk11rty5eb+qtsRuesvD492CA1AUA5jRw5zz2OSGPJSt1vv5qnbBbDVFHX10k7Xq+vKnq9Ytnd7FOUtlVKSVdBq5Ynkx1TZjv8/SwB5N9t/j+ZqZoJVIEeKP+YUccAPOikHutRRNu91t2AgqsxwIDAQAB\n-----END PUBLIC KEY-----\n'}
DEBUG:kasa.aestransport:Request {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDal8slelSWpAjM+TXxqVVul2TWk11rty5eb+qtsRuesvD492CA1AUA5jRw5zz2OSGPJSt1vv5qnbBbDVFHX10k7Xq+vKnq9Ytnd7FOUtlVKSVdBq5Ynkx1TZjv8/SwB5N9t/j+ZqZoJVIEeKP+YUccAPOikHutRRNu91t2AgqsxwIDAQAB\n-----END PUBLIC KEY-----\n'}}

@bdraco bdraco merged commit f045696 into python-kasa:master Jan 23, 2024
@rytilahti rytilahti added the bug Something isn't working label Jan 23, 2024
rytilahti added a commit to rytilahti/python-kasa that referenced this pull request Jan 25, 2024
[Full Changelog](python-kasa/python-kasa@0.6.0.1...0.6.1)

Release highlights:
* Support for tapo wall switches
* Support for unprovisioned devices
* Performance and stability improvements

**Implemented enhancements:**

- Add support for tapo wall switches \(S500D\) [\python-kasa#704](python-kasa#704) (@bdraco)
- Add new cli command 'command' to execute arbitrary commands [\python-kasa#692](python-kasa#692) (@rytilahti)
- Allow raw-command and wifi without update [\python-kasa#688](python-kasa#688) (@rytilahti)
- Generate AES KeyPair lazily [\python-kasa#687](python-kasa#687) (@sdb9696)
- Add reboot and factory\_reset to tapodevice [\python-kasa#686](python-kasa#686) (@rytilahti)
- Try default tapo credentials for klap and aes [\python-kasa#685](python-kasa#685) (@sdb9696)
- Sleep between discovery packets [\python-kasa#656](python-kasa#656) (@sdb9696)

**Fixed bugs:**

- Do not crash on missing geolocation [\python-kasa#701](python-kasa#701) (@rytilahti)
- Fix P100 error getting conn closed when trying default login after login failure [\python-kasa#690](python-kasa#690) (@sdb9696)

**Documentation updates:**

- Add protocol and transport documentation [\python-kasa#663](python-kasa#663) (@sdb9696)
- Document authenticated provisioning [\python-kasa#634](python-kasa#634) (@rytilahti)

**Closed issues:**

- Consider handshake as still valid on ServerDisconnectedError [\python-kasa#676](python-kasa#676)
- AES Transport creates the key even if the device is offline [\python-kasa#675](python-kasa#675)
- how to provision new Tapo plug devices? [\python-kasa#565](python-kasa#565)
- Space out discovery requests [\python-kasa#229](python-kasa#229)

**Merged pull requests:**

- Add additional L900-10 fixture [\python-kasa#707](python-kasa#707) (@bdraco)
- Replace rich formatting stripper [\python-kasa#706](python-kasa#706) (@bdraco)
- Add support for the S500 [\python-kasa#705](python-kasa#705) (@bdraco)
- Fix overly greedy \_strip\_rich\_formatting [\python-kasa#703](python-kasa#703) (@bdraco)
- Ensure login token is only sent if aes state is ESTABLISHED [\python-kasa#702](python-kasa#702) (@bdraco)
- Update readme fixture checker and readme [\python-kasa#699](python-kasa#699) (@rytilahti)
- Fix test\_klapprotocol test duration [\python-kasa#698](python-kasa#698) (@sdb9696)
- Renew the handshake session 20 minutes before we think it will expire [\python-kasa#697](python-kasa#697) (@bdraco)
- Add --batch-size hint to timeout errors in dump\_devinfo [\python-kasa#696](python-kasa#696) (@sdb9696)
- Add L930-5 fixture [\python-kasa#694](python-kasa#694) (@bdraco)
- Add fixtures for L510E [\python-kasa#693](python-kasa#693) (@bdraco)
- Refactor aestransport to use a state enum [\python-kasa#691](python-kasa#691) (@bdraco)
- Update transport close/reset behaviour [\python-kasa#689](python-kasa#689) (@sdb9696)
- Check README for supported models [\python-kasa#684](python-kasa#684) (@rytilahti)
- Add P100 test fixture [\python-kasa#683](python-kasa#683) (@bdraco)
- Make dump\_devinfo request batch size configurable [\python-kasa#681](python-kasa#681) (@sdb9696)
- Add updated L920 fixture [\python-kasa#680](python-kasa#680) (@bdraco)
- Update fixtures from test devices [\python-kasa#679](python-kasa#679) (@bdraco)
- Show discovery data for state with verbose [\python-kasa#678](python-kasa#678) (@rytilahti)
- Add L530E\(US\) fixture [\python-kasa#674](python-kasa#674) (@bdraco)
- Add P135 fixture [\python-kasa#673](python-kasa#673) (@bdraco)
- Rename base TPLinkProtocol to BaseProtocol [\python-kasa#669](python-kasa#669) (@sdb9696)
- Add 1003 \(TRANSPORT\_UNKNOWN\_CREDENTIALS\_ERROR\) [\python-kasa#667](python-kasa#667) (@rytilahti)
@rytilahti rytilahti mentioned this pull request Jan 25, 2024
rytilahti added a commit that referenced this pull request Jan 25, 2024
[Full Changelog](0.6.0.1...0.6.1)

Release highlights:
* Support for tapo wall switches
* Support for unprovisioned devices
* Performance and stability improvements

**Implemented enhancements:**

- Add support for tapo wall switches \(S500D\) [\#704](#704) (@bdraco)
- Add new cli command 'command' to execute arbitrary commands [\#692](#692) (@rytilahti)
- Allow raw-command and wifi without update [\#688](#688) (@rytilahti)
- Generate AES KeyPair lazily [\#687](#687) (@sdb9696)
- Add reboot and factory\_reset to tapodevice [\#686](#686) (@rytilahti)
- Try default tapo credentials for klap and aes [\#685](#685) (@sdb9696)
- Sleep between discovery packets [\#656](#656) (@sdb9696)

**Fixed bugs:**

- Do not crash on missing geolocation [\#701](#701) (@rytilahti)
- Fix P100 error getting conn closed when trying default login after login failure [\#690](#690) (@sdb9696)

**Documentation updates:**

- Add protocol and transport documentation [\#663](#663) (@sdb9696)
- Document authenticated provisioning [\#634](#634) (@rytilahti)

**Closed issues:**

- Consider handshake as still valid on ServerDisconnectedError [\#676](#676)
- AES Transport creates the key even if the device is offline [\#675](#675)
- how to provision new Tapo plug devices? [\#565](#565)
- Space out discovery requests [\#229](#229)

**Merged pull requests:**

- Add additional L900-10 fixture [\#707](#707) (@bdraco)
- Replace rich formatting stripper [\#706](#706) (@bdraco)
- Add support for the S500 [\#705](#705) (@bdraco)
- Fix overly greedy \_strip\_rich\_formatting [\#703](#703) (@bdraco)
- Ensure login token is only sent if aes state is ESTABLISHED [\#702](#702) (@bdraco)
- Update readme fixture checker and readme [\#699](#699) (@rytilahti)
- Fix test\_klapprotocol test duration [\#698](#698) (@sdb9696)
- Renew the handshake session 20 minutes before we think it will expire [\#697](#697) (@bdraco)
- Add --batch-size hint to timeout errors in dump\_devinfo [\#696](#696) (@sdb9696)
- Add L930-5 fixture [\#694](#694) (@bdraco)
- Add fixtures for L510E [\#693](#693) (@bdraco)
- Refactor aestransport to use a state enum [\#691](#691) (@bdraco)
- Update transport close/reset behaviour [\#689](#689) (@sdb9696)
- Check README for supported models [\#684](#684) (@rytilahti)
- Add P100 test fixture [\#683](#683) (@bdraco)
- Make dump\_devinfo request batch size configurable [\#681](#681) (@sdb9696)
- Add updated L920 fixture [\#680](#680) (@bdraco)
- Update fixtures from test devices [\#679](#679) (@bdraco)
- Show discovery data for state with verbose [\#678](#678) (@rytilahti)
- Add L530E\(US\) fixture [\#674](#674) (@bdraco)
- Add P135 fixture [\#673](#673) (@bdraco)
- Rename base TPLinkProtocol to BaseProtocol [\#669](#669) (@sdb9696)
- Add 1003 \(TRANSPORT\_UNKNOWN\_CREDENTIALS\_ERROR\) [\#667](#667) (@rytilahti)
@sdb9696 sdb9696 deleted the fix_p100_error branch February 20, 2024 09:43
rytilahti pushed a commit that referenced this pull request Jun 4, 2024
Fixes an issue reported by @bdraco with the P100 not working in the
latest branch:

`[Errno None] Can not write request body for HOST_REDACTED,
ClientOSError(None, 'Can not write request body for
URL_REDACTED'))`

Issue caused by the number of multi requests going above the default
batch of 5 and the P100 not being able to handle the second multi
request happening immediately as it closes the connection after each
query (See #690 for
similar issue). This introduces a small wait time on concurrent requests
once the device has raised a ClientOSError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants