Search code examples
python-3.xbinancebinance-api-client

python-binance client.get_historical_klines error


hello everyone i have a weird problem when calling get_historical_klines from binance-python in my code. i've tried to run the my personal PC (windows) and it worked but on my VPS it's showing this error this is the part where my program crash. i've tried different versions of python (3.8,3.9) and different versions of python-binance (1.0.15) module but same problem i've made sure that my PC ( windows) and my VPS (Ubuntu 20.04) has the same version of python and python-binance module. Any suggestions why this is happening and how can i solve it ?

ticker= "BTCUSDT"
interval= Client.KLINE_INTERVAL_1DAY
depth= "200 week ago"
raw= client.get_historical_klines(ticker, interval, depth)
raw= pd.DataFrame(raw)
Traceback (most recent call last):
  File "/home/ubuntu/hedi.py", line 74, in <module>
    raw= client.get_historical_klines(ticker, interval, depth)
  File "/usr/local/lib/python3.9/dist-packages/binance/client.py", line 932, in get_historical_klines
    return self._historical_klines(symbol, interval, start_str, end_str=end_str, limit=limit, klines_type=klines_type)
  File "/usr/local/lib/python3.9/dist-packages/binance/client.py", line 964, in _historical_klines
    start_ts = convert_ts_str(start_str)
  File "/usr/local/lib/python3.9/dist-packages/binance/helpers.py", line 72, in convert_ts_str
    return date_to_milliseconds(ts_str)
  File "/usr/local/lib/python3.9/dist-packages/binance/helpers.py", line 23, in date_to_milliseconds
    d: Optional[datetime] = dateparser.parse(date_str, settings={'TIMEZONE': "UTC"})
  File "/usr/local/lib/python3.9/dist-packages/dateparser/conf.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/dateparser/__init__.py", line 61, in parse
    data = parser.get_date_data(date_string, date_formats)
  File "/usr/local/lib/python3.9/dist-packages/dateparser/date.py", line 428, in get_date_data
    parsed_date = _DateLocaleParser.parse(
  File "/usr/local/lib/python3.9/dist-packages/dateparser/date.py", line 178, in parse
    return instance._parse()
  File "/usr/local/lib/python3.9/dist-packages/dateparser/date.py", line 182, in _parse
    date_data = self._parsers[parser_name]()
  File "/usr/local/lib/python3.9/dist-packages/dateparser/date.py", line 196, in _try_freshness_parser
    return freshness_date_parser.get_date_data(self._get_translated_date(), self._settings)
  File "/usr/local/lib/python3.9/dist-packages/dateparser/date.py", line 234, in _get_translated_date
    self._translated_date = self.locale.translate(
  File "/usr/local/lib/python3.9/dist-packages/dateparser/languages/locale.py", line 131, in translate
    relative_translations = self._get_relative_translations(settings=settings)
  File "/usr/local/lib/python3.9/dist-packages/dateparser/languages/locale.py", line 158, in _get_relative_translations
    self._generate_relative_translations(normalize=True))
  File "/usr/local/lib/python3.9/dist-packages/dateparser/languages/locale.py", line 172, in _generate_relative_translations
    pattern = DIGIT_GROUP_PATTERN.sub(r'?P<n>\d+', pattern)
  File "/usr/local/lib/python3.9/dist-packages/regex/regex.py", line 700, in _compile_replacement_helper
    is_group, items = _compile_replacement(source, pattern, is_unicode)
  File "/usr/local/lib/python3.9/dist-packages/regex/_regex_core.py", line 1736, in _compile_replacement
    raise error("bad escape \\%s" % ch, source.string, source.pos)
regex._regex_core.error: bad escape \d at position 7```

Solution

  • this is resolved in dateparser version 1.1.1, released on 17 March 2022. Please upgrade your dateparser to 1.1.1.