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
An Ri
  • 406
  • 5
  • 13

4 Answers4

17

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.

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.

Olga Nosova
  • 136
  • 1
  • 2
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.

PApostol
  • 2,152
  • 2
  • 11
  • 21
  • 2
    `dateparser==1.1.1` still requires `regex==2022.3.2`. Same error with `regex==2022.6.2`. See Mehmet's answer (https://stackoverflow.com/a/71504213/11750716) – Jean Monet Jun 13 '22 at 15:27
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)
MediaVince
  • 479
  • 1
  • 8
  • 13