grahamwetzler / smart-meter-texas

Package to connect to and retrieve data from the unoffical Smart Meter Texas API
MIT License
13 stars 13 forks source link

Timeout Error on Requesting Login Token Upgrading from 0.4.2 to 0.4.3 #40

Closed rtp4jc closed 3 years ago

rtp4jc commented 3 years ago

Description

I'm just using the example code to get my meter readings and I was able to get the readings easily before. However, when I upgraded to version 0.4.3 I got asyncio.exceptions.TimeoutError exceptions after this debug log:

DEBUG:smart_meter_texas:Requesting login token

What I Did

I just ran python get_meter_reading.py and waited until the timeout occurred. This didn't happen in version 0.4.1 or 0.4.2. Here's the full stack trace:

Traceback (most recent call last):
  File "lambda_function.py", line 54, in <module>
    lambda_handler(None, None)
  File "lambda_function.py", line 46, in lambda_handler
    meter_values = loop.run_until_complete(main())
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "lambda_function.py", line 26, in main
    await client.authenticate()
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/site-packages/smart_meter_texas/__init__.py", line 166, in authenticate
    await self._init_websession()
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/site-packages/smart_meter_texas/__init__.py", line 126, in _init_websession
    await self.websession.get(BASE_URL, headers=self._agent_headers())
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 860, in start
    self._continue = None
  File "/home/ryan/Applications/Anaconda3/envs/EU/lib/python3.8/site-packages/aiohttp/helpers.py", line 596, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

A minor note that I also replicated this in an environment on the Ubuntu shell of Windows Subsystem for Linux with the exact same result.

grahamwetzler commented 3 years ago

It's a known issue. The user agent in previous versions was hard coded but it seems that the API does not like the number of connections from the Home Assistant integration. 0.4.3 was an attempt to add variation to the user agent, however it did not solve the problem.

https://github.com/home-assistant/core/issues/40348

meyerrj commented 3 years ago

Any news on this issue? I was looking to implement the Home Assistant integration, but it seems this long standing issue is still preventing it from being used.

grahamwetzler commented 3 years ago

Sorry no, I haven't been able to work around the API blocking.

meyerrj commented 3 years ago

I'm not sure if this will help or not, but I did find this document: https://www.smartmetertexas.com/Smart_Meter_Texas_Interface_Guide.pdf

Also, in their Help Center, there is this regarding the APIs:

image

Their requirement for a Static IP Address and the Signed Digital Certificate issued by a CA and associated with SMT sounds like a bit of a deal breaker for most users...

grahamwetzler commented 3 years ago

Right, that's why I built this library to connect to the API that the website uses.

adamfeldman commented 3 years ago

@grahamwetzler, thank you for building this lib!

Hopes and plans aren't action, but I plan to take a shot at fixing this in the next couple weeks.

I'm very excited about the new energy monitoring features in Home Assistant.

grahamwetzler commented 3 years ago

Thanks @adamfeldman. Let me know if I can help.

meyerrj commented 3 years ago

I've submitted a PR that appears to fix the issue.

Apparently the www subdomain is the cause of the timeout. Thanks to @elmigbot on the related Home Assistant issue for identifying the likely cause. https://github.com/home-assistant/core/issues/40348

grahamwetzler commented 3 years ago

Thanks to @meyerrj this is now resolved.