Of course there are those with ill-intent who prey on tourists everywhere in the world and in some places they seem to be bolder, or have more free rein, than in other places, more's the pity.
I rather like Morocco, but I speak (or used to speak - not used it for a few years) reasonable conversational Arabic, and I think that is a huge factor that plays in my advantage.
I went over to Morocco for the first time when I was visiting a QARNS friend stationed in Gib; they were 'warned off' going especially alone or in all-female small groups but having lived in Saudi Arabia through most of the 70s I wasn't going to be put off, so as Sue had leave, we went. We travelled all over the country by bus and train without the slightest problem. Well, I say 'without the slightest problem' BUT I made Sue dress appropriately when 'in public' which was far more covered than she had expected, and always asked where stuff like the 'family section' was in cafes and the 'women's seats' on the bus. So we (somewhat) avoided labelling ourselves.
When some young blokes started harassing us when we were lost in a souk, I turned to them, hands on hips and asked them, in Arabic (in what I was later told was a very educated 'university' accent!) how they would like their sisters and mothers to be spoken to like that.
They were stunned. They looked at each other and said to each other 'she speaks Arabic!' and I retorted 'Yes I do, why are you so surprised? I understand it too. Someone once told me the Maghrebi were not as polite as true Arabs and now I think maybe they were right.'
Long story cut short, we ended up being entertained by their mothers and sisters every day for the few days we were in Marrakesh! Ridiculous but that's the way it is ... although the technology which surrounds us may be 21st century, outside the boundaries of the hotel, cultural and behavioural expectations have not maintained pace in massive, probably most, parts of the world.
A friend, 20 years younger than me, who is a keen cyclist, planned to go on a cycling holiday to Morocco by herself in 2015, so I sat her down and gave her a lecture about clothing and behaviour when off her bike, and made her promise to me that before she cycled through any town or stopped in any village or even a farmhouse, before she got off her bike she WOULD put on a mid-calf length wrap-around skirt and a loose, very thin, cotton shawl over her head, shoulders and upper arms. She thanked me when she came back; she said she initially thought what I had said was ridiculous but after after her first day she thought she'd try my instructions and said they were a great success.