Error in heroku [regex._regex_core.error: bad escape \d at position 7] when using python-binance
Asked Answered
C

4

10

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 too 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
Cutcliffe answered 16/3, 2022 at 13:43 Comment(0)
X
12

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.

Xenia answered 16/3, 2022 at 18:49 Comment(1)
Can you provide links to your source of information?Consuelaconsuelo
B
18

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.

Buie answered 16/3, 2022 at 21:3 Comment(1)
Thanks for this fix! I'm still experiencing the same issue. I tried installing the latest version of regex, 2024.4.16, and still got the same problems in dateparser. However, I then realized that I'm only using dateparser==0.7.6 because homeassistant-cli I'm using has a requirement that dateparser<0.8,>=0.7.1,. This seems to be in error. Forcibly upgrading to dateparser==1.2.0 seems to work fine with homeassistant-cli and fixes the bug, despite its supposed version requirements. Figured this might help others. Cheers!Cycle
X
12

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.

Xenia answered 16/3, 2022 at 18:49 Comment(1)
Can you provide links to your source of information?Consuelaconsuelo
S
7

There is now the new version of dateparser==1.1.1 which accounts for the regex package update. Upgrading to the latest version of dateparser resolved the issue for me.

Sinking answered 22/3, 2022 at 14:48 Comment(1)
dateparser==1.1.1 still requires regex==2022.3.2. Same error with regex==2022.6.2. See Mehmet's answer (https://mcmap.net/q/1038864/-error-in-heroku-regex-_regex_core-error-bad-escape-d-at-position-7-when-using-python-binance)Weakly
P
0

I pass the time in millisecond timestamp and it works perfectly. Make sure to convert to integer type. Happy analysis and happy trades!

from datetime import datetime

from_time = int(datetime.strptime("2022-07-17", "%Y-%m-%d").timestamp()*1000)

to_time = int(datetime.strptime("2022-07-18", "%Y-%m-%d").timestamp()*1000)

client.get_historical_klines(symbol="BTCUSDT", interval="1h", start_str=from_time, end_str=to_time, limit=1000)
Printmaker answered 19/7, 2022 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.