Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

[Dúvida] dados = pd.read_csv(URL)

Prezados, por favor, como corrigir esse erro?

Código: Insira aqui a descrição dessa imagem para ajudar na acessibilidadeimport os import pandas as pd from os.path import join 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 = 'FNYZ68U5Q9DYDALDF9HZBP5UQ'

URL = join("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/", f"{city}/{data_inicio}/{data_fim}?unitGroupp=metric&include=days&key=(key)&contentType=csv")

dados = pd.read_csv(URL) print(dados.head())

Erro: keniakodel@vmware-ubuntu:~/Documents/datapipeline$ python3 extrai_info_clima.py Traceback (most recent call last): File "extrai_info_clima.py", line 21, in dados = pd.read_csv(URL) File "/home/keniakodel/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 912, in read_csv return _read(filepath_or_buffer, kwds) File "/home/keniakodel/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 577, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/home/keniakodel/.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/keniakodel/.local/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1661, in _make_engine self.handles = get_handle( File "/home/keniakodel/.local/lib/python3.8/site-packages/pandas/io/common.py", line 716, in get_handle ioargs = _get_filepath_or_buffer( File "/home/keniakodel/.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/keniakodel/.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 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:

Desde já agradeço a atenção.

2 respostas
solução!

Oi, Kenia

Linha 19, em "(key)", use chaves "{key} "

Agradecida!