The rock python had just killed and eaten a goat, but perhaps more troubling, the reptile had crushed and consumed its meal within shouting distance of a school. Something had to be done.

So worried residents in Jalpaiguri, a city in northeast India, called Sanjay Dutta, the local forest ranger, according to Reuters.

As onlookers stared, Dutta corralled the 18-foot snake with an animal-control pole, then used thick gloves to grab the snake’s head and pick it up.

Crisis averted. All Dutta had to do was put it into a sack for quick transport back to the wild, perhaps to the banks of the nearby Teesta River, where it wouldn’t pose a threat to humans.

Instead, Dutta draped the snake around his neck.

It was time for a celebratory selfie.

Some residents hoisted smartphones, motioning for others to cram in closer to the forest ranger and the beast he’d captured. One man smoked what may have been a celebratory cigarette. A child sat on a man’s shoulders, craning to get into the picture.

And through it all, the rock python remained a rock python.

Suddenly perched on the very vulnerable neck area of a mammal, the snake made a few efforts to wrap itself around the man.

Dutta batted the snake’s body away, at one point holding the powerful reptile at bay while he smiled for the camera.

But moments later, he was clearly in distress.

The snake managed to wrap one coil completely around Dutta’s neck. Meanwhile, the reptile had jerked its tail free of a man assisting the forest ranger, further entangling Dutta.

Scared residents who, moments earlier, had crammed in for a photo screamed and sprinted away.

“It’s okay,” Dutta screamed, according to the Sun. “It’s all okay.”

Clearly, it was not.

As he walked away from the crowd, the python tightened its grip.

Dutta resisted the urge to panic or struggle, movements that would just make the snake more aggressive.

“I was not scared for even a moment,” Dutta told Agence France-Presse. “Because had I panicked, it could have been fatal.”

It wasn’t. With a little help, Dutta managed to free himself. The end of the video shows him walking away, shaken but breathing. He and an assistant kept a firm grip on the powerful snake.

But Dutta’s experience was a brief insight into deadly perils Indians face everyday.

Not from pythons — from selfies.

As The Washington Post’s Annie Gowen reported, about half of the world’s selfie-related deaths occurred in India, as smartphone-enabled humans ignore the dangers around them in search of the perfect shot.

Gowen wrote:

In 2015, Indians taking selfies died while posing in front of an oncoming trainin a boat that tipped over at a picnic, on a cliff that gave way and crumbled into a 60-foot ravine and on the slippery edge of a scenic river canal. Also, in September, a Japanese tourist trying to take a selfie fell down steps at the Taj Mahal, suffering fatal head injuries.

Mumbai police said this week that they had identified more than a dozen “no-selfie zones” around India’s largest city after three young girls were swept out into the Arabian Sea while taking selfies in a rocky part of the Bandra area (on Jan. 9). One of the young women is presumed to have drowned, as did a man who jumped in to save them.

Other nations and cities have also made an effort to alert people to the dangers of selfies. Russia, for example, created a series of posters to advise people about places where it is probably not a good idea to snap a selfie.

The poster shows images of clearly doomed stick figures taking pictures while jumping in front of oncoming trains, dangling off roofs and, in one case, falling down a flight of stairs. One stick figure snaps a selfie while brandishing a gun. Another has scaled power lines for a picture.

“We tried visually, in the form of pictograms, to depict the most traumatic cases of creating selfies,” the Russian Ministry of Internal Affairs said in a news release.

There is no image of a stick figure snapping a photo while being crushed by a rock python — and no need for one, thanks to Dutta’s escape.

He was not seriously harmed by his too-close encounter with the reptile — and apparently was unfazed by its sudden aggression.

Afterward, he released the reptile into the wild. But he didn’t have a sack to carry the snake in, so he simply put it in his car.

Read more:

Authorities: Gold miners at a bar bragged about slaughtering members of a reclusive Brazilian tribe

A man was crushed to death beneath his mother’s coffin

Scientists have identified the 50-foot creature that washed up on an Indonesian beach

Giant pythons keep attacking people in Indonesia — and humans might be to blame