python-binance client.get_historical_klines 错误

python-binance client.get_historical_klines error

大家好我在代码中从 binance-python 调用 get_historical_klines 时遇到了一个奇怪的问题。我已经尝试 运行 我的个人电脑 (windows) 并且它有效,但在我的 VPS 上它显示此错误这是我的程序崩溃的部分。我尝试了不同版本的 python (3.8,3.9) 和不同版本的 python-binance (1.0.15) 模块但同样的问题 我已经确保我的电脑 (windows) 和我的 VPS (Ubuntu 20.04) 具有相同版本的 python 和 python-binance 模块。 有什么建议为什么会这样吗?我该如何解决?

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```

尝试将模块正则表达式从 2022.3.15 降级到 2022.3.2

问候

此问题已在 2022 年 3 月 17 日发布的 dateparser version 1.1.1 中解决。请将您的 dateparser 升级到 1.1.1。

我遇到了同样的问题,我通过卸载当前版本的正则表达式 (2022.3.15) 并安装较低版本 (2022.3.2) 解决了这个问题。

命令:

pip uninstall regex -y
pip install regex==2022.3.2