rodrigosantosbr

[Py] API - Brazilian Cep / Zip Code

Apr 6th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import json
  2. import requests
  3.  
  4. cep="65081264"
  5. url = "http://cep.la/{}".format(cep)
  6. headers = {
  7.     'Accept': 'application/json',
  8. }
  9.  
  10. try:
  11.     response = requests.get(url, headers=headers)
  12.     print(response.json())
  13.     if response.status_code == 200:
  14.         response.encoding = 'utf-8'
  15.         json_response = response.json()
  16.         uf = json_response["uf"]
  17.         cidade = json_response["cidade"]
  18.         bairro = json_response["bairro"]
  19.         logradouro = json_response["logradouro"]
  20.         print(uf)
  21.         print(cidade)
  22.         print(bairro)
  23.         print(logradouro)
  24. except Exception as e:
  25.     print(e)
Add Comment
Please, Sign In to add comment