benleb/surepy

Installation/setup error?

rjclocks opened this issue · 2 comments

Installed surepy using pip and used the Library example code from the README.
I am getting a load of errors and am not sure what the issue is. I used my credentials for the Sure Pet account, but get thefollowing when I try to run this example.

Traceback (most recent call last): File "Z:\programming\python\surepy_testing\catflap_test.py", line 42, in <module> asyncio.run(main()) File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete return future.result() File "Z:\programming\python\surepy_testing\catflap_test.py", line 24, in main pets: List[Pet] = await surepy.get_pets() File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\__init__.py", line 297, in get_pets return [pet for pet in (await self.get_entities()).values() if isinstance(pet, Pet)] File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\__init__.py", line 349, in get_entities if response := await self.sac.call(method="GET", resource=MESTART_RESOURCE): File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\client.py", line 218, in call self._auth_token = await self.get_token() File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\client.py", line 188, in get_token raise SurePetcareError() Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001888E364550> Traceback (most recent call last): File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 116, in __del__ self.close() File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 746, in call_soon self._check_closed() File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 510, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed surepy.exceptions.SurePetcareError

Found the problem: Windows and asynchio

Solution: Add the following into the end of the code

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.run(main())

Ran up against a second chellenge. The code now starts to run, but throws a different error:

Traceback (most recent call last): File "Z:\programming\python\surepy_testing\catflap_test.py", line 42, in <module> asyncio.run(main()) File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete return future.result() File "Z:\programming\python\surepy_testing\catflap_test.py", line 24, in main pets: List[Pet] = await surepy.get_pets() File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\__init__.py", line 297, in get_pets return [pet for pet in (await self.get_entities()).values() if isinstance(pet, Pet)] File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\__init__.py", line 349, in get_entities if response := await self.sac.call(method="GET", resource=MESTART_RESOURCE): File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\client.py", line 218, in call self._auth_token = await self.get_token() File "C:\Users\rob_r\AppData\Roaming\Python\Python39\site-packages\surepy\client.py", line 188, in get_token raise SurePetcareError() surepy.exceptions.SurePetcareError