Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import requests
def validate_field(field):
cep = "".join(field.replace("-"," ").split())
if cep.isdigit() and len(cep) == 8:
return cep
raise Exception('CEP "{field}" Format Invalid'.format(field=field))
CEP_SEARCH = validate_field('01001001')
API_CEP_BASE_URL = 'https://api.findcep.com/v1/cep/{cep}.json'
headers = {'Referer': 'https://your-site.com'}
cep_request = requests.get(API_CEP_BASE_URL.format(cep=CEP_SEARCH) , headers=headers)
print(cep_request.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.