Can a solo female traveler carry a knife or pepper spray to be able defend of herself when she is on the road or when hitchhiking, or it is illegal?
This totally depends on the country, each country has different rules. Wikipedia has a page dedicated to Knife legislation. Check the countries you will visit before brining your knife with you.
Same thing goes for pepper spray, it is different from one country to another, again Wikipedia has a page dedicated to pepper spray.
Stun guns are a bad choice as they are illegal in most European countries.
As @MeNoTalk already mentioned, the answer differs from country to country. I was expecting that the answer be that both are not allowed. Apparently even pepper spray is allowed in some EU countries.
Personally I would say both are really drastic measures to protect yourself and unnecessary. In general you would not need those to protect yourself.
In Europe self-defence is approached with proportionality. If some one would attack you without a knife or pepperspray and you would use either a knife or pepperspray to defend yourself, it could be that you end up being treated as the offender.
Those area's where you might be at risk, knife or pepperspray wouldn't help either. It is better to find out where the no-go area's are.
If you need to use a knife for any thing else then to protect your self, then it is allowed to carry a knife. If you are for example a scuba diver, you are allowed to cary double bladed knifes, BUT packed together with your diving gear in the back of your car.
I answer about usage in France, not about legal aspects as I am not a lawyer.