Requests.get failing when run by service but not manually

I am trying to debug an info-beamer node for providing digital signage for a convention, which pulls session information periodically from the guidebook.com API. When SSH’d into my test PI, the API request succeeds, running it via:

> info-beamer-155321772 /space/root # NODE=root ./service

However, when running the same service under service.root, I get exception during the request, watching logread -f:

Feb 28 01:48:23 info-beamer-155321772 user.notice service.root: [hosted.py] sending 'root/guidebook/update:{"status":"failed-guidebook-fetch","exception":"HTTPSConnectionPool(host=\'builder.guidebook.com\', port=443): Max retries exceeded with url: /open-api/v1/locations/?guide=195965

I had restarted root.service via sv i /service/service.root to make sure I had the latest service code running. Is there anything about running as service.root that would be different?

Somewhat related, is there a way to view Python’s print statements when running as a service? Thank you!

You probably don’t have the “network” permission in node.json. A package service can’t access the network by default. If you add that, be sure to also modify the service file itself, so the OS reinstalls your service. Otherwise the change in node.json has no effect.

Ack, rookie move on my part. Thanks!

The request is working, though I think something else is hanging later on in my service. Is there a way to see Python print statements or exceptions? logread doesn’t seem to have that.

If you log to stdout, it is probably buffered and only ends up in logread each 4K chunk or so. Stderr is usually line buffered and you should see output immediately. The alternative is to run the service interactive to see what it is doing:

cd /service/service.root
sv d . # terminate the info-beamer manage instance of the service 
./run shell # enters the service’s environment
./service

That was really helpful to figure out what’s going on (and I found Package services - info-beamer after your response. Sorry again). I’m getting a permission denied trying to write a pickle file into the package directory. I guess I should try using the SCRATCH directory, but I don’t think I’ve run into a permission denied before while writing into the node.

You really shouldn’t get that error. Writing to the package directory (or more precisely, writing to ., so the current directory, as a package service is always run with its installation directory as current directory) should always work and is a usual way of exchanging data between a package service and the info-beamer process.

The only reason that might happen is if you already have a file with the same name included within the package itself: A package service can only create or change new files, not overwrite files included in the package. Maybe that’s the case?

Hi lousimons,
Maybe if you try to add the “run-as-root” permission in node.json it will work, although the documentation does not recommend it in most cases, that should work so that the “service” can write the file in the package directory. It worked for me in a similar case.

1 Like

I think @infobeamer-fw was right, though I didn’t think I had a file with the same name. In a previous commit of the package, I did have a filename collision, but I thought I had removed it. Either way, saving the file into /STASH in the node is working and fits my use case better.