FIRST came a report on September 1st that the United States’ National Security Agency (NSA) had been monitoring the phone calls and e-mails of Brazil’s president, Dilma Rousseff, and other senior officials. Then came evidence that the NSA appeared to be spying on Petrobras, Brazil’s national oil company. An angry Ms Rousseff demanded explanations, an apology and a guarantee that these “illegal practices” would cease, as a condition for going ahead with a long-planned state visit to Washington next month. Although Barack Obama said he understood the concerns raised by Brazil, more explicit contrition was apparently not forthcoming in a 20-minute phone call on September 16th. The two leaders announced the “postponement” of the visit.

But with no date rescheduled, that looked more like cancellation. Thus the first international result of a stream of revelations from Edward Snowden, a fugitive NSA contractor, about the agency’s industrial-scale snooping (relayed in this case via a Brazilian television programme), has been a further deterioration in the often-awkward relations between the two largest countries in the Americas.

Few in Brazil were surprised by Ms Rousseff’s decision. In the circumstances “being seen in an evening gown with President Obama” risked seeming “submissive and weak”, according to Oliver Stuenkel, an international-relations specialist at the Getúlio Vargas Foundation, a university. Two things magnified the risk: the possibility of further revelations from Mr Snowden’s trove of documents, and a presidential election in a year’s time at which Ms Rousseff, who is less popular than she was, will seek a second term. Furthermore, Brazil had no big issues to negotiate during the visit and some in Latin America will applaud Ms Rousseff for standing up to the United States.

The short-term cost of the spying row looks greater for Mr Obama. Brazil is mulling a bid from Boeing to provide its air force with 36 Super Hornet jet fighters. Officials might now prefer rival bidders from France or Sweden. Then there is the interest of American energy companies in bidding for a slice of a giant deep-sea oilfield at an auction next month. Brazil’s energy regulator says the integrity of the auction has not been compromised by the snooping on Petrobras. But nationalist members of Brazil’s congress may not agree.

The revelations have also triggered a debate in Brazil about the way the internet operates. What really worries the government is that the “huge vulnerabilities in its protection systems online were left exposed”, according to Rubens Barbosa, a former Brazilian ambassador to Washington. Brazil “has one of the most vulnerable and unprotected internet infrastructures in the world”, according to a recent paper by IPEA, a government-linked think-tank.

Officials are now talking about laying fibre-optic cables to Latin American countries and Europe so that Brazil’s international online traffic bypasses the United States. They also plan to tackle the country’s shortage of internet exchange points, which makes eavesdropping easier. They have ordered Brazil’s post office to launch a free encrypted e-mail service to try to compete with Gmail and others. Petrobras said it would spend 21 billion reais ($9.5 billion) over five years to improve its data security.

Ms Rousseff has urged the Congress to approve a long-proposed regulatory code for the internet. Telecoms companies resist this, because it enshrines network neutrality, which would prevent them from charging more for premium content. Its supporters say the code would make it easier to punish, if not prevent, online spying. The president also wants the bill to include a requirement that Brazilians’ electronic data be stored in Brazil and not abroad.

One risk for Brazil from the spying row is that it prompts protectionism: in the 1980s a military government barred the import of computers in a failed attempt to foster a local industry. The difference, according to Matias Spektor, a Brazilian professor of international relations at King’s College in London, is that the proposed code is the subject of a fierce democratic debate. An internet providers’ lobby, which includes Microsoft and Google, says the code would further raise the high costs of using the internet in Brazil.

American officials say in private that only the naive were astonished to hear that the NSA monitors other governments. Some in Washington will see the cancellation of the first state visit by a Brazilian president since 1995 as a disproportionate reaction. It may confirm their view that Brazil is a perennially difficult partner.

Ironically, Ms Rousseff has taken some pains to improve the relationship with the United States, damaged by the efforts of Luiz Inácio Lula da Silva, her predecessor, to negotiate with Iran over its nuclear programme. Mr Spektor thinks that no Brazilian president could have gone ahead with the visit in the circumstances. Nevertheless, he sees in the spying affair “a very unhelpful confirmation of very deep-rooted fears that the United States is out to stop Brazil from rising”.

Those fears, which American officials say are groundless, are much more intense in Brasília than in the country at large. Policy has become more nationalist under the left-wing Workers’ Party, in power since 2002. One result is that Brazil’s relations with the United States are more distant than those of many other emerging powers, such as India, South Africa or Turkey. That is odd, since the two countries are important trading and investment partners.

Mr Barbosa insists that the affair will not prevent both sides continuing with business as usual. But it is unlikely that the newly arrived American ambassador in Brasília will be invited to present her credentials to Ms Rousseff soon. However justified, the cancellation of the president’s visit represents an opportunity forgone.