python-binance client.get_historical_klines 错误

发布于 2025-01-15 02:30:15 字数 3276 浏览 2 评论 0原文

大家好,我在代码中从 binance-python 调用 get_historical_klines 时遇到了一个奇怪的问题。我尝试运行我的个人电脑(Windows)并且它可以工作,但在我的 VPS 上它显示此错误,这是我的程序崩溃的部分。我尝试过不同版本的 python (3.8,3.9) 和不同版本的 python-binance (1.0.15) 模块,但遇到同样的问题 我已确保我的 PC(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```

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花开柳相依 2025-01-22 02:30:15

此问题已在 3 月 17 日发布的 dateparser 版本 1.1.1 中解决2022。请将您的日期解析器升级到 1.1.1。

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

别念他 2025-01-22 02:30:15

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

2022.3.2

try to downgrade the module regex from 2022.3.15 to 2022.3.2

regards

待"谢繁草 2025-01-22 02:30:15

我遇到了同样的问题,我解决了它,取消了正则表达式的当前版本(2022.3.15)并安装了较低版本(2022.3.2)。

命令:

pip uninstall regex -y
pip install regex==2022.3.2

I had the same problem and i solve it unistaling the currect version of regex (2022.3.15) and instaling a lower version (2022.3.2).

Commands:

pip uninstall regex -y
pip install regex==2022.3.2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文