Skip to content

Commit 824fc4e

Browse files
committed
Merge pull request #36 from CodingForChange/erro_503
Tratando queda dos correios
2 parents f050a70 + 33b8b0a commit 824fc4e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

PostmonServer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from bottle import route, run, response
22
from CepTracker import CepTracker
3+
from requests import ConnectionError
34

45
from database import MongoDb as Database
56

@@ -34,8 +35,12 @@ def verifica_cep(cep):
3435
result = db.get_one(cep, fields={ '_id': False })
3536

3637
if not result or not result.has_key('v_date') or expired(result):
37-
for item in _get_info_from_correios(cep):
38-
db.insert_or_update(item)
38+
try:
39+
for item in _get_info_from_correios(cep):
40+
db.insert_or_update(item)
41+
42+
except ConnectionError:
43+
response.status = '503 Servico Temporariamente Indisponivel'
3944

4045
result = db.get_one(cep, fields={ '_id': False, 'v_date': False })
4146

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This file is placed here by pip to indicate the source was put
2+
here by pip.
3+
4+
Once this package is successfully installed this source code will be
5+
deleted (unless you remove this file).

0 commit comments

Comments
 (0)