Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Correçao de bug de SSL e Atualizaçao do README
Browse files Browse the repository at this point in the history
  • Loading branch information
caputchinefrobles committed Sep 18, 2020
1 parent 1067fc8 commit 4eda6fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
doufinder.cfg
downloads

26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Script que pesquisa no Diário Oficial da União termos de interesse e notifica
- urllib3
- mailer
- chardet (pdfminer)
- certifi

`pip install pdfminer.six urllib3 mailer chardet`
`pip install pdfminer.six urllib3 mailer chardet certifi`

## Utilização

Expand Down Expand Up @@ -60,3 +61,26 @@ Sem estes parâmetros não é possível o envio das ocorrências aos interessado

O parâmetro `DOWNLOAD_DIR` é necessário para que a função de pesquisa offline funcione.

## ERRO DE CERTIFICADO

Recentemente, o acesso às páginas do jornal do diário oficial foi convertido
para HTTPS. A cadeia de certificados usada para o host `pesquisa.in.gov.br`
não está incluida nos certificados do sistema operacional (pode ser que esteja
incluída nos certificados do browser). Desta forma, o python não consegue
validar o certificado fornecido pelo resultado do "request".

Para contornar o problema, é necessário incluir a cadeia de certificados de
https://pesquisa.in.gov.br no arquivo ca-cert.pem utilizado pelo python:
1. Acesse pelo browser a url [https://pesquisa.in.gov.br](https://pesquisa.in.gov.br)
2. Extraia a cadeia de certificados
3. Abra um shell python e execute os seguintes comantes:
a. ```python import certifi```
b. ```python certifi```
c. ```python print(certifi.where())```
4. O resultado deve ser o caminho do arquivo cacert.pem que o python usa.
Ex.: .local/lib/python3.8/site-packages/certifi/cacert.pem
5. Adicionar o conteúdo do certificado extraído no passo 2 ao final do
arquivo cacert.pem apontado pelo passo 3.

Executando estes passos de maneira correta, o erro de validação de certificado
deve ser resolvido.
7 changes: 4 additions & 3 deletions classes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from globais import *
import datetime
import re
import certifi

class Servidor:
def __init__(self, nome = '', emails_notificacao = [], termos_pesquisa = []):
Expand All @@ -17,7 +18,7 @@ class Pesquisa:

def __init__(self, lista_servidores=None, diretorio_offline=None, offline=False, strdata=None):
self.lista = lista_servidores
self.url = "http://pesquisa.in.gov.br/imprensa/servlet/INPDFViewer?jornal={0}&pagina={1}&data={2}&captchafield=firstAccess"
self.url = "https://pesquisa.in.gov.br/imprensa/servlet/INPDFViewer?jornal={0}&pagina={1}&data={2}&captchafield=firstAccess"

if strdata is None:
self.data_pesquisa = datetime.datetime.now().date().strftime("%d/%m/%Y")
Expand Down Expand Up @@ -50,7 +51,7 @@ def processar(self, jornal, pagina_inicio=1, pagina_fim=1100, extra=False):
'Host':'pesquisa.in.gov.br',
'Upgrade-Insecure-Requests':'1'}

http = urllib3.PoolManager()
http = urllib3.HTTPSConnectionPool(host="pesquisa.in.gov.br", port=443, ca_certs=certifi.where())
full_url = self.url.format(jornal,pagina, self.data_pesquisa)

print ("Seção {0}, Página {1}".format(jornal, pagina))
Expand Down Expand Up @@ -141,6 +142,6 @@ def enviar_ocorrencias(self, remetente, servidor_smtp, porta, usuario, senha):
for ocorrencia in termo.ocorrencias:
msg += '\t' + ocorrencia + '\n'

if msg is not '' :
if msg != '' :
enviar_email(msg, servidor.emails_notificacao,
remetente, servidor_smtp, porta, usuario, senha, False)

0 comments on commit 4eda6fc

Please sign in to comment.