` import os from os.path import join import pandas as pd from datetime import datetime, timedelta
#intervalo de datas data_inicio = datetime.today() data_fim = data_inicio + timedelta(days=7)
#formatando datas data_inicio = data_inicio.strftime('%Y-%m-%d') data_fim = data_fim.strftime('%Y-%m-%d')
city = 'Boston' key = '4M2SCKPZXWG6YSPT7ETNKRY27'
URL = join("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/", f"{city}/{data_inicio}/{data_fim}?unitGroup=metric&include=days&key={key}&contentType=csv")
dados = pd.read_csv(URL) print(dados.head)
lucca@lucca-virtual-machine:~/Documents/alura/apache airflow 1:orquestrando seu primiero pipeline/datapipeline$ python3 extrai_infos_clima.py
Traceback (most recent call last): File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/usr/lib/python3.8/http/client.py", line 1256, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output self.send(msg) File "/usr/lib/python3.8/http/client.py", line 951, in send self.connect() File "/usr/lib/python3.8/http/client.py", line 1418, in connect super().connect() File "/usr/lib/python3.8/http/client.py", line 922, in connect self.sock = self._create_connection( File "/usr/lib/python3.8/socket.py", line 787, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "extrai_infos_clima.py", line 20, in dados = pd.read_csv(URL) File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 912, in read_csv return _read(filepath_or_buffer, kwds) File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 577, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1407, in init self._engine = self._make_engine(f, self.engine) File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1661, in _make_engine self.handles = get_handle( File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/common.py", line 716, in get_handle ioargs = _get_filepath_or_buffer( File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/common.py", line 368, in _get_filepath_or_buffer with urlopen(req_info) as req: File "/home/lucca/.local/lib/python3.8/site-packages/pandas/io/common.py", line 270, in urlopen return urllib.request.urlopen(*args, **kwargs) File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.8/urllib/request.py", line 525, in open response = self._open(req, data) File "/usr/lib/python3.8/urllib/request.py", line 542, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/usr/lib/python3.8/urllib/request.py", line 1397, in https_open return self.do_open(http.client.HTTPSConnection, req, File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>