jabesq-org / pyatmo

Simple API to access Netatmo weather station data from any python script (for Netatmo information, see www.netatmo.com)
MIT License
27 stars 29 forks source link

Cannot access data with sudo #223

Closed simeoncapy closed 11 months ago

simeoncapy commented 2 years ago

Hello, I don't know if this problem is linked to pyatmo or my raspberry pi configuration. But when I try to access my weather station data, if I'm running the script without sudo, I get them. If I use sudo, I get an empty table. I installed pyatmo with and without sudo: (sudo) pip3 install pyatmo.

When I call this line print("\tWS-OBJ**** STATIONS " + str(self.weatherData.stations)) (weatherData is a pyatmo.WeatherStationData object), I get the result below:

# without sudo
pi@raspberrypi:~/GitHub/project $ python3 linkWeatherStation.py
WS-OBJ**** STATIONS {'ADDR': {'_id': 'ADDR', 'station_name': 'name', ...}}

# with sudo
pi@raspberrypi:~/GitHub/project $ sudo python3 linkWeatherStation.py
WS-OBJ**** STATIONS defaultdict(<class 'dict'>, {})

Is there a reason the station is not responding in sudo mode?

Thanks in advance

cgtobi commented 2 years ago

No there is no reason I could think of why this should not work, so I assume this has something to do with the host OS. When run in a container (as root) this works just fine.

simeoncapy commented 2 years ago

Ok, thanks, it removes one side of the problem then! So, I'll check the configuration of my RPi, python and so on.

cgtobi commented 2 years ago

I would not recommend to run scripts as root, but I am sure you are aware of that.

simeoncapy commented 2 years ago

Sorry for the late reply! I know it's not good. But I have some scripts/libraries that need to be used with sudo on my Raspberry pi. I try to avoid it as much as possible.

I realised another stranger behaviour: I run my code WITHOUT sudo, I cannot use the function update:

AttributeError: 'WeatherStationData' object has no attribute 'update'

If I remove the update function, I can get my data.

If I run WITH sudo, I have to use the update function. If I don't use it, the station list is empty

defaultdict(<class 'dict'>, {})

Why the update function behaves like that?

cgtobi commented 2 years ago

Please try with the latest version.

cgtobi commented 11 months ago

There has not been any update for over a year. I'm closing this now. Pleas reopen if this persists to be an issue or open a new issue.