Bom dia, pessoal. Tudo bem? Sou nova na área de dados, e logo quando rodei o primeiro print para testar a saída da API, eu obtive erro. Segue meu código e erro abaixo:
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 as datas
data_inicio = data_inicio.strftime('%Y-%m-%d')
data_fim = data_fim.strftime('%Y-%m-%d')
city = 'Boston'
key = 'PPV8HWZNZWKHHZ8LREXX3RBC6M'
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())
erro no terminal:
/bin/python3 /home/anagii/Documents/datapipeline/extrair_dados_clima.py
Traceback (most recent call last):
File "/home/anagii/Documents/datapipeline/extrair_dados_clima.py", line 20, in <module>
dados = pd.read_csv(URL)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv
return _read(filepath_or_buffer, kwds)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 605, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1442, in __init__
self._engine = self._make_engine(f, self.engine)
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1735, in _make_engine
self.handles = get_handle(
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/common.py", line 713, in get_handle
ioargs = _get_filepath_or_buffer(
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/common.py", line 363, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File "/home/anagii/.local/lib/python3.8/site-packages/pandas/io/common.py", line 265, 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 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
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 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401:
Poderiam me ajudar, por gentileza?
Agradeço desde já!