Forums

Response 403 in a whitelist endpoint

Hi,

I'm new to django and python anywhere and I am stuck in a situation. I'm getting <Response [403]> in a whitelisted site (portaltransparencia.gov.br). I'm using their API to scrap some data. The code runs perfectly in my machine, but I started getting this error on python anywhere. I try adding the user-agent, but it had no effect.

Here's the snippet where it fails:

url = 'http://api.portaldatransparencia.gov.br/api-de-dados/despesas/documentos-por-favorecido' ano = request.POST['year'] fase = 3 codigoPessoa = '#######' pagina = 1 ordenacaoResultado = 4

parameters ={'ano':ano,'codigoPessoa':codigoPessoa,'fase':fase,'ordenacaoResultado':ordenacaoResultado,'pagina':pagina}

headers = {'chave-api-dados':'#######','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}

resultado = requests.get(url=url, params=parameters,headers=headers) x = pd.DataFrame(resultado.json()) time.sleep(1)

Send us the link to the official documentation for the endpoint in question and we'll see what we can do.