Skip to content

Commit 68905b5

Browse files
committed
Passa auth para o packtrack.
1 parent 7479964 commit 68905b5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

PackTracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
from database import MongoDb as Database
99

1010

11-
def correios(track, backend=None):
11+
def correios(track, backend=None, auth=None):
1212
if backend is None:
1313
backend = os.getenv('ECT_BACKEND')
14-
encomenda = packtrack.Correios.track(track, backend=backend)
14+
encomenda = packtrack.Correios.track(track, backend=backend, auth=auth)
15+
1516
if not encomenda:
1617
raise ValueError(u"Encomenda nao encontrada.")
1718
if not encomenda.status:

PostmonServer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ def cidade(sigla_uf, nome):
192192
def track_pack(provider, track):
193193
response.headers['Access-Control-Allow-Origin'] = '*'
194194
if provider == 'ect':
195+
auth = (
196+
request.headers.get('x-correios-usuario'),
197+
request.headers.get('x-correios-senha'),
198+
)
199+
if auth == (None, None):
200+
auth = None
201+
195202
try:
196-
historico = PackTracker.correios(track)
203+
historico = PackTracker.correios(track, auth=auth)
197204
except (AttributeError, ValueError):
198205
message = "404 Pacote %s nao encontrado" % track
199206
logger.exception(message)

0 commit comments

Comments
 (0)