0
I am trying to make an application to query a list of cep’s that I have, but when ex: cep=40717000 does not exist is displayed an error and I can’t proceed to the next record of the table, can anyone please help? Thank you
import requests
import json
import pyodbc
conn = pyodbc.connect("DRIVER={SQL Server};Server=54.233.154.67;database=xxxxx;uid=yyyyy;pwd=zzzz")
cursor = conn.cursor()
cursor.execute('select * from cep_sem_referencia')
for row in cursor.fetchall():
cep = row[1]
r = requests.get("https://viacep.com.br/ws/%s/json/" % cep)
#try:
if r.status_code == requests.codes.ok:
j = json.loads(r.text)
cep1 = j['cep']
uf = j['uf']
cursor = conn.cursor()
cursor.execute("INSERT INTO endereco VALUES('%s','%s')" % (cep1, uf))
conn.comit()
else:
print('cep não encontrado')
#except Exception:
#print('')
"an error is displayed", what mistake?
– Woss