Danielhiversen / pyTibber

Async Python 3 library for Tibber
GNU General Public License v3.0
96 stars 34 forks source link

aiohttp.client_exceptions.ClientConnectorError #197

Closed marcelcastrobr closed 2 years ago

marcelcastrobr commented 2 years ago

Hi, I am running pytibber version o. on docker with python:3.9-slim-buster (Python 3.9.13). My requirements.txt file has: aiohttp==3.8.1 aiosignal==1.2.0 async-timeout==4.0.2 attrs==22.1.0 charset-normalizer==2.1.0 frozenlist==1.3.0 graphql-subscription-manager==0.4.3 idna==3.3 multidict==6.0.2 numpy==1.23.1 pandas==1.4.3 psycopg2==2.9.3 python-dateutil==2.8.2 pyTibber boto3 >= 1.20.13 argparse AWSIoTPythonSDK==1.5.2

The code is the same you propose as example: _async def main(): access_token = ACCESS_TOKEN tibber_connection = tibber.Tibber(access_token) await tibber_connection.update_info()

home = tibber_connection.get_homes()[0]
await home.update_info()

await home.update_price_info()
tibberPrice = home.current_price_info

# covert dict to json and send to AWSIoTCore
tibberPrice['address'] = TIBBERADDRESS
tibberPrice['timestamp'] = strftime("%Y-%m-%d %H:%M:%S", gmtime())
messageJson = json.dumps(tibberPrice, indent = 4)

#Send to AWSIoT
myawsclient.publish(topic, messageJson)
print('Published topic %s: %s\n' % (topic, messageJson))

await tibber_connection.close_connection()__

if name == 'main': loop = asyncio.get_event_loop() while True: loop.run_until_complete(main()) time.sleep(60)

The following error occurs: Published topic tibber/price: { "energy": 3.8703, "tax": 0.9775, "total": 4.8478, "startsAt": "2022-09-05T11:00:00.000+02:00", "level": "NORMAL", "address": "XX", "timestamp": "2022-09-05 09:57:54" }

hosts = await asyncio.shield(host_resolved)

File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 880, in _resolve_host

addrs = await self._resolver.resolve(host, port, family=self._family)

File "/usr/local/lib/python3.9/site-packages/aiohttp/resolver.py", line 33, in resolve

infos = await self._loop.getaddrinfo(

File "/usr/local/lib/python3.9/asyncio/base_events.py", line 861, in getaddrinfo

return await self.run_in_executor(

File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run

result = self.fn(*self.args, **self.kwargs)

File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo

for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

socket.gaierror: [Errno -2] Name or service not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/usr/src/app/./PubSub_Tibber_Price.py", line 80, in

loop.run_until_complete(main())

File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete

return future.result()

File "/usr/src/app/./PubSub_Tibber_Price.py", line 49, in main

await tibber_connection.update_info()

File "/usr/local/lib/python3.9/site-packages/tibber/init.py", line 132, in update_info

if (res := await self._execute(query)) is None:

File "/usr/local/lib/python3.9/site-packages/tibber/init.py", line 105, in _execute

return await self._execute(document, variable_values, retry - 1)

File "/usr/local/lib/python3.9/site-packages/tibber/init.py", line 105, in _execute

return await self._execute(document, variable_values, retry - 1)

File "/usr/local/lib/python3.9/site-packages/tibber/init.py", line 98, in _execute

resp = await self.websession.post(API_ENDPOINT, **post_args)

File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 535, in _request

conn = await self._connector.connect(

File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 542, in connect

proto = await self._create_connection(req, traces, timeout)

File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 907, in _create_connection

_, proto = await self._create_direct_connection(req, traces, timeout)

File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection

raise ClientConnectorError(req.connection_key, exc) from exc

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.tibber.com:443 ssl:default [Name or service not known]

Unclosed client session

client_session: <aiohttp.client.ClientSession object at 0xffff9a7bc340>

Unclosed client session

client_session: <aiohttp.client.ClientSession object at 0xffff9a733070>

Unclosed client session

client_session: <aiohttp.client.ClientSession object at 0xffff9a733d00>

Unclosed client session

client_session: <aiohttp.client.ClientSession object at 0xffff98657910>appening:

Any tips about why this is happening? The error appears everytime I run the code.

Danielhiversen commented 2 years ago

Cannot connect to host api.tibber.com:443 ssl:default [Name or service not known]

Either issue at Tibber or your network