pyatmo icon indicating copy to clipboard operation
pyatmo copied to clipboard

Cannot access data with sudo

Open simeoncapy opened this issue 2 years ago • 5 comments

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

simeoncapy avatar Mar 02 '22 04:03 simeoncapy

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.

cgtobi avatar Mar 02 '22 06:03 cgtobi

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

simeoncapy avatar Mar 02 '22 07:03 simeoncapy

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

cgtobi avatar Mar 02 '22 10:03 cgtobi

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?

simeoncapy avatar Mar 15 '22 09:03 simeoncapy

Please try with the latest version.

cgtobi avatar Jun 19 '22 17:06 cgtobi

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.

cgtobi avatar Nov 26 '23 20:11 cgtobi