Git Product home page Git Product logo

Comments (19)

edumucelli avatar edumucelli commented on September 3, 2024 1

Devido a última atualização dos dados de CEPs agora os dados do CEPAberto agora estão de acordo com as dos Correios. Portanto, o resultado indicado no site foi atualizado:

{'latitude': '-23.4336578', 'longitude': '-45.0838481', 'estado': {'sigla': 'SP'}, 'cep': '11680000', 'cidade': {'nome': 'Ubatuba', 'ddd': 12, 'ibge': '3555406'}, 'altitude': 4.8}

Não existe mais o logradouro: Ubatuba, pois evidamente este logradouro não existe. Isso foi uma adaptação que eu havia feito na primeira versão dos dados. Agora está mais correto. Acredito que o problema foi corrigido. Vou deixar o issue fechado. Caso ainda esteja funcionando posso abri-lo novamente.

from cepaberto-api-examples.

kelvindules avatar kelvindules commented on September 3, 2024

Aparentemente há um problema no lado servidor para esse recurso (recebendo 500). Acho que será necessária ajuda do @edumucelli

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Com a ajuda de um cara, actualizei e melhorei os códigos, mas duas pesquisas pararam de funcionar:

<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') 
{

    if (array_key_exists('cep', $_POST)) 
    {
        $method = 'cep';
        $url = 'http://www.cepaberto.com/api/v2/ceps.json?cep=' . urlencode($_POST['cep']);

        echo '<h2>The city and the state of this zip is ... </h2>';
    } 
    
    else if ($method = array_key_exists('cidade', $_POST) && array_key_exists('estado', $_POST)) 
    {
        $method = 'locale';
        $url ='http://www.cepaberto.com/api/v3/address?estado=' . urlencode($_POST['estado']) . '&cidade=' . urlencode($_POST['cidade']);
        echo '<h2>The zip of this city and this state is... </h2>';
    };

    if (isset($method)) 
    {
        $token = 'a392d94bcbf94158e519e1a1555d8e59';
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Token token="' . $token . '"']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // you really should have more error handling here
        $output = curl_exec($ch);
        $result = json_decode($output);

        echo '<div class="result">';
        switch ($method) 
        {
            case 'cep':
                echo $result->cidade, ', ', $result->estado;
                break;
            case 'locale':
                echo $result->cep;
                break;
        }
        echo '</div>';
    } 
    
    else 
    {
        echo '<p>Invalid/incomplete form data.</p>';
    }

} 

else 
{
// handle that we didn't come from the form properly here
}

?>

from cepaberto-api-examples.

edumucelli avatar edumucelli commented on September 3, 2024

Ola @gusbemacbe e @kelvindules, não consegui reproduzir. Talvez eu não tenha entendido o problema, mas pra mim a seguinte requisição funciona:

curl http://cepaberto.com/api/v3/address\?cidade\=Ubatuba\&estado\=SP -H 'Authorization: Token token="SEU_TOKEN"'

retorna

{"altitude":4.8,"cep":"11680000","latitude":"-23.4336578","longitude":"-45.0838481","logradouro":"Ubatuba","bairro":null,"cidade":{"ddd":12,"ibge":"3555406","nome":"Ubatuba"},"estado":{"sigla":"SP"}}

Para simplificar a abordagem ao problema, primeiro tente com curl.

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Funcionou, mas compare os endereços, porque você utilizou a letra \.

No seu site, sugeriu-nos e está sem a letra \:

http://www.cepaberto.com/api/v3/address?estado=SP&cidade=Ubatuba

Agora, você utilizou a letra \ aqui neste comentário e este endereço funcionou:

http://cepaberto.com/api/v3/address\?cidade\=Ubatuba\&estado\=SP

Testarei com letra \ pata ver se funcionará.

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Acabei de testar. Tampouco funcionaram as pesquisas.

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Agora entendi, utilizei a versão 3 em vez da versão 2, por isso, versão 3 não está disponível para a pesquisa de cidade e estado para achar o CEP. Testarei a versão 2.

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Acabei de testar, nenhuma pesquisa funciona com ambas as versões por causa do isset ou curl_setopt(). Mas encontrei os erros oos qual depurei em seguida:

[Tue Mar 20 20:20:33 2018] PHP Notice:  Undefined variable: ch in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 39
[Tue Mar 20 20:20:33 2018] PHP Warning:  curl_setopt() expects parameter 1 to be resource, null given in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 39
[Tue Mar 20 20:20:33 2018] PHP Notice:  Undefined variable: ch in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 40
[Tue Mar 20 20:20:33 2018] PHP Warning:  curl_setopt() expects parameter 1 to be resource, null given in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 41
[Tue Mar 20 20:20:33 2018] PHP Notice:  Undefined variable: ch in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 43

[Tue Mar 20 20:20:33 2018] PHP Warning:  curl_setopt() expects parameter 1 to be resource, null given in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 43
[Tue Mar 20 20:20:33 2018] PHP Notice:  Undefined variable: ch in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 45
[Tue Mar 20 20:20:33 2018] PHP Warning:  curl_exec() expects parameter 1 to be resource, null given in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 45
[Tue Mar 20 20:20:33 2018] PHP Notice:  Trying to get property 'cidade' of non-object in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 51
[Tue Mar 20 20:20:33 2018] PHP Notice:  Trying to get property 'estado' of non-object in /home/ubuntu/Programmation/PHP/teste-cep/result.php on line 51
[Tue Mar 20 20:20:33 2018] 127.0.0.1:47092 [200]: /result.php

Acho que tenho de criar duas páginas sem isset e utilizarei a mesma versão 3 compatível com ambas as pesquisas para evitar o conflito.

from cepaberto-api-examples.

edumucelli avatar edumucelli commented on September 3, 2024

from cepaberto-api-examples.

gusbemacbe avatar gusbemacbe commented on September 3, 2024

Em ambas a versões, sem ou com \, curl funcionou no terminal, mas não em PHP, talvez por causa do isset e do curl_setopt().

Talvez você tente testar com meu pequeno projecto que partilharei...

teste-correios.zip

from cepaberto-api-examples.

kelvindules avatar kelvindules commented on September 3, 2024

Em C#,

var client = new WebClient{ Encoding = Encoding.UTF8 };
client.Headers.Add(HttpRequestHeader.Authorization, token);
var requestResult = client.DownloadString("http://www.cepaberto.com/api/v3/address?estado=AL&cidade=Maceio");

Está retornando Erro 500, porém buscando por CEP funciona normal:

var requestResult = client.DownloadString("http://www.cepaberto.com/api/v3/cep?cep=11680000");

from cepaberto-api-examples.

edumucelli avatar edumucelli commented on September 3, 2024

@gusbemacbe @kelvindules corrigido. Agradeço por reportar o problema. No caso de cidades que não tem CEP agora retorna JSON vazio, ao invés de 500.

from cepaberto-api-examples.

kelvindules avatar kelvindules commented on September 3, 2024

@edumucelli show! Obrigado pela atenção.

from cepaberto-api-examples.

Armstrongtech10 avatar Armstrongtech10 commented on September 3, 2024

Olá pessoal cepAbert não existe mais, teria uma API similar a esta?
Obrigado pela ajuda.

from cepaberto-api-examples.

edumucelli avatar edumucelli commented on September 3, 2024

@Armstrongtech10 existe ainda, corrigi o problema.

from cepaberto-api-examples.

AdstonOliveira avatar AdstonOliveira commented on September 3, 2024

A consulta por endereço e cidade esta retornando vazio para todos.

from cepaberto-api-examples.

RobertMyles avatar RobertMyles commented on September 3, 2024

Sim, tá vazio:

curl http://cepaberto.com/api/v3/address\?cidade\=Ubatuba\&estado\=SP -H 'Authorization: Token token="TOKEN"'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://cepaberto.com/api/v3/address?cidade=Ubatuba&amp;estado=SP">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at cepaberto.com Port 80</address>
</body></html>

from cepaberto-api-examples.

edumucelli avatar edumucelli commented on September 3, 2024

Desculpe a demora, você pode tentar usar https ao invés de http? Suspeito que a redireção 301 (http -> https) não está sendo seguida (que deveria ser por padrão na biblioteca cliente).

from cepaberto-api-examples.

RobertMyles avatar RobertMyles commented on September 3, 2024

Sim:

curl https://cepaberto.com/api/v3/address\?cidade\=Ubatuba\&estado\=SP -H 'Authorization: Token token="XXX"'

Agora retorna:

{}

from cepaberto-api-examples.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.