Home > Software design >  Error in heroku [regex._regex_core.error: bad escape \d at position 7] when using python-binance
Error in heroku [regex._regex_core.error: bad escape \d at position 7] when using python-binance

Time:03-17

I tried to upload my python code (Binance trade-bot) on Heroku, but there is an error oссured. Could someone help me, please?

from binance.client import Client
from datetime import datetime

client = Client(api,key)
symbol = 'IOSTUSDT'

for i in client.futures_historical_klines(symbol, Client.KLINE_INTERVAL_1MINUTE, '2022-03-16'):
    print(i)

The error is

2022-03-16T13:37:45.890497 00:00 app[worker.1]: Traceback (most recent call last):
2022-03-16T13:37:45.890552 00:00 app[worker.1]:   File "/app/code.py", line 14, in <module>
2022-03-16T13:37:45.890743 00:00 app[worker.1]:     for i in client.futures_historical_klines(symbol, Client.KLINE_INTERVAL_1MINUTE, '2022-03-16'):
2022-03-16T13:37:45.890758 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/binance/client.py", line 5709, in futures_historical_klines
2022-03-16T13:37:45.892661 00:00 app[worker.1]:     return self._historical_klines(symbol, interval, start_str, end_str=end_str, limit=limit, klines_type=HistoricalKlinesType.FUTURES)

---here to much text--

2022-03-16T13:37:45.894613 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/dateparser/languages/locale.py", line 131, in translate
2022-03-16T13:37:45.894755 00:00 app[worker.1]:     relative_translations = self._get_relative_translations(settings=settings)
2022-03-16T13:37:45.894769 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/dateparser/languages/locale.py", line 158, in _get_relative_translations
2022-03-16T13:37:45.894912 00:00 app[worker.1]:     self._generate_relative_translations(normalize=True))
2022-03-16T13:37:45.894927 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/dateparser/languages/locale.py", line 172, in _generate_relative_translations
2022-03-16T13:37:45.895085 00:00 app[worker.1]:     pattern = DIGIT_GROUP_PATTERN.sub(r'?P<n>\d ', pattern)
2022-03-16T13:37:45.895100 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/regex/regex.py", line 700, in _compile_replacement_helper
2022-03-16T13:37:45.895586 00:00 app[worker.1]:     is_group, items = _compile_replacement(source, pattern, is_unicode)
2022-03-16T13:37:45.895600 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/regex/_regex_core.py", line 1736, in _compile_replacement
2022-03-16T13:37:45.896352 00:00 app[worker.1]:     raise error("bad escape \\%s" % ch, source.string, source.pos)
2022-03-16T13:37:45.896430 00:00 app[worker.1]: regex._regex_core.error: bad escape \d at position 7

CodePudding user response:

I had the same issue - regex library was updated from 2022.3.2 to 2022.3.15. You can set version in requirements for a while issue will fixed in next version.

CodePudding user response:

I started to have the exactly same issue today. As Olga mentioned, this started to happen after version 2022.3.15 of regex library is released.

I investigated the root cause by checking call stack and I saw that dateparser library is using regex for parsing datetime strings.

I tried to run only code snippet in below it also gave me the same error. Therefore I could localize the error.

dateparser.parse('1 Jan, 2020', settings={'TIMEZONE': "UTC"})

What you can do is simply uninstalling regex library and installing the older version. You can also add version in your requirements.txt file.

pip uninstall regex -y
pip install regex==2022.3.2

For detailed versions of regex library.

  • Related