web-push-libs/vapid

Not able to run vapid --sign claim.json

halhwadi opened this issue · 6 comments

I'm following this link to create web push notification for my App, right now I'm stuck in step2 (creating public and private key) because I can't run this command(even tough I have implemented successfully the vapid

vapid --sign claim.json

I got this error when running this command!! 'vapid' is not recognized as an internal or external command,

Env(windows 10)

Hi!

virtualenv (or venv for Python3) is a command that installs python to a local directory. When you run python from that directory, all the changes are confined to that directory. This means that you don't accidentally change anything globally.

I don't know exactly how you're running python on windows (from PowerShell, or WSL, or Linux in a HyperV VM), but it sounds like the vapid executable script isn't in your path. I'm guessing you're probably running it outside of the path you installed it. If you like, virtualenv does provide an activate command (I think it's activate.bat on windows) which will add the local python binary to your path so long as you have that session open. (It doesn't add it globally forever, just to that window.)

Using keys that are generated on a site is possible (so long as they're the right encryption format), but it's not very secure. If you're just using them for something personal or teaching yourself how to code, there's no problem. I would not suggest that you use those keys for anything important or as part of anything you give to someone else. It's also a VERY good idea to use a different key for VAPID and a different key for encrypting the message, for the same security reasons.

Also, when you run virtualenv or python -m venv you have to give a directory you want python to install into.
(for example: python3 -m venv venv_dir will create a new directory called venv_dir and install python under venv_dir. You would then call venv_dir/bin/python3 to use that new, virtual environment python.

It can be confusing because many examples will use something like python3 -m venv venv which creates a new directory called venv that contains python. It sounds a bit like you're still learning python, which is good! You may want to read up a bit more about how some of the install and tooling work, though, because some of it can be hard to understand.

Try looking up things like python3 "setup.py" or python3 venv tutorial. From personal experience, I find windows to be a very good host system for running linux virtual machines to do my development. I've hit far too many bumps trying to get tools to understand how windows wants to do things.

Like every language, python has it's own quirks. One of them is that because so many system things depend on Python, it's A Good Idea to do development in a protected "virtual environment". There, you can go crazy, make mistakes, and otherwise break things without breaking the system needed by the OS. Life becomes a good deal better when you take time to sort things out.

Getting the message can be a bit different for each platform. For Firefox, there are a few examples that are pretty straight-forward. You can try looking at https://serviceworke.rs/web-push.html for how to do things. It sounds like you're fairly close. For a lot of reasons, you need to create a separate "Service Worker" file that handles getting the actual message. That will run on a separate, limited thread. It then can communicate with your application thread using something like postMessage

I'm not sure I can really help much with that part, but there are lots of good tutorials out there.

closing as inactive.