0

I'm trying to make a program that requests a meteorology message to one free API made by the Brazilian air force and shows it to users. This program it works great at three first hours, but after, it shows erros in sequence and don't actualizes the message.

try:
            #caso o resultado anterior não gere dados, sera feita nova conexão
            print(self.horapesquisa)
            objurl = urllib.request.urlopen(f'http://redemet.decea.gov.br//api/consulta_automatica/index.php?local={self.sigla_localidade}&msg=metar&data_ini={self.horapesquisa}&data_fim={self.horapesquisa}')
            if objurl.getcode() == 200:
                self.dados = objurl.read()
                self.dados = str(self.dados)

                inicio = self.dados.find('METAR')
                fim = self.dados.find('=')
                self.dados = self.dados[inicio:fim+1]
        except:

error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 839, in callit
    func(*args)
  File "c:\Users\claud\OneDrive\Documentos\meuusprojetos\METAR\main.py", line 30, in infa
    met = modulos.Metar(localidade,verificador_atraso)
  File "c:\Users\claud\OneDrive\Documentos\meuusprojetos\METAR\modulos\modulos.py", line 41, in __init__
    objurl = urllib.request.urlopen(f'http://redemet.decea.gov.br//api/consulta_automatica/index.php?local={self.sigla_localidade}&msg=metar&data_ini={self.horapesquisa}&data
_fim={self.horapesquisa}')
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1377, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\claud\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>

1 Answers1

0

Some sites with API have rate limit. I think you reached this limit. Try:

import socket
print(socket.getaddrinfo('redemet.decea.gov.br', 80))

If you can connect, you should see the following output:

[(<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('177.203.219.24', 80)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('177.203.219.24', 80)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_RAW: 3>,
  0,
  '',
  ('177.203.219.24', 80))]
Corralien
  • 109,409
  • 8
  • 28
  • 52