Skip to content

Commit

Permalink
Passa auth para o packtrack.
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Jun 29, 2017
1 parent 7479964 commit 68905b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions PackTracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from database import MongoDb as Database


def correios(track, backend=None):
def correios(track, backend=None, auth=None):
if backend is None:
backend = os.getenv('ECT_BACKEND')
encomenda = packtrack.Correios.track(track, backend=backend)
encomenda = packtrack.Correios.track(track, backend=backend, auth=auth)

if not encomenda:
raise ValueError(u"Encomenda nao encontrada.")
if not encomenda.status:
Expand Down
9 changes: 8 additions & 1 deletion PostmonServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,15 @@ def cidade(sigla_uf, nome):
def track_pack(provider, track):
response.headers['Access-Control-Allow-Origin'] = '*'
if provider == 'ect':
auth = (
request.headers.get('x-correios-usuario'),
request.headers.get('x-correios-senha'),
)
if auth == (None, None):
auth = None

try:
historico = PackTracker.correios(track)
historico = PackTracker.correios(track, auth=auth)
except (AttributeError, ValueError):
message = "404 Pacote %s nao encontrado" % track
logger.exception(message)
Expand Down

0 comments on commit 68905b5

Please sign in to comment.