Skip to content

erro ao obter dados de moedas usando o metodo currency.get #27

@txicos

Description

@txicos

Erro ao obter dados de moedas. por exemplo:

from bcb import currency
currency.get(symbols='USD', start='2025-10-06', end='2025-10-09')

http://www4.bcb.gov.br/Download/fechamento/M20260323.csv
<?xml version="1.0" encoding="pt-br"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
<head>
<title>Requisição inválida!</title>
<link rev="made" />
<style>

....

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/bcb/currency.py", line 173, in get
    df1 = _get_symbol(symbol, start, end)
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/bcb/currency.py", line 107, in _get_symbol
    cid = _get_currency_id(symbol)
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/bcb/currency.py", line 101, in _get_currency_id
    all_currencies = get_currency_list()
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/bcb/currency.py", line 80, in get_currency_list
    df = pd.read_csv(StringIO(res.text), delimiter=";")
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1026, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 626, in _read
    return parser.read(nrows)
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1923, in read
    ) = self._engine.read(  # type: ignore[attr-defined]
  File "/home/ubuntu/extracao/extracao-env/lib/python3.10/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 234, in read
    chunks = self._reader.read_low_memory(nrows)
  File "pandas/_libs/parsers.pyx", line 838, in pandas._libs.parsers.TextReader.read_low_memory
  File "pandas/_libs/parsers.pyx", line 905, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 874, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas/_libs/parsers.pyx", line 891, in pandas._libs.parsers.TextReader._check_tokenize_status
  File "pandas/_libs/parsers.pyx", line 2061, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 9, saw 3

Aparentemente a url que ele usa para baixar os dados está inválida. Talvez tenha sido descontinuada.

python == 3.10
python-bcb == 0.3.3
ubuntu == 22.04

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions