Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't compare offset-naive and offset-aware datetimes #4

Open
goblin opened this issue Oct 1, 2018 · 2 comments
Open

TypeError: can't compare offset-naive and offset-aware datetimes #4

goblin opened this issue Oct 1, 2018 · 2 comments

Comments

@goblin
Copy link

goblin commented Oct 1, 2018

When trying to download some videos from Ipla (not all of them), I got the following stacktrace:

  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/bin/rtv", line 11, in <module>
    sys.exit(main())
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/rtv/cli.py", line 22, in main
    rtv.load(set(urls))
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python
3.6/site-packages/rtv/rtvdownloader.py", line 28, in load
    extractor.run()
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/rtv/extractors/common.py", line 59, in run
    entries = self.extract()
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/rtv/extractors/ipla.py", line 110, in extract
    'date': self.get_date(),
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/rtv/extractors/ipla.py", line 62, in get_date
    found_dates = search_dates(description, languages=['pl'])
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/search/__init__.py", line 33, in search_dates
    result = _search_with_detection.search_dates(text=text, languages=languages, settings=settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/conf.py", line 81, in wrapper
    return f(*args, **kwargs)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/search/search.py", line 221, in search_dates
    settings=settings)}
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/search/search.py", line 153, in search_parse
    original=original, translated=translated, settings=settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/search/search.py", line 116, in parse_found_objects
    parsed_item = self.parse_item(parser, item, translated[i], parsed, need_relative_base)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/search/search.py", line 102, in parse_item
    parsed_item = parser.get_date_data(item)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/date.py", line 404, in get_date_data
    locale, date_string, date_formats, settings=self._settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/date.py", line 177, in parse
    return instance._parse()
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/date.py", line 187, in _parse
    date_obj = parser()

  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/date.py", line 209, in _try_parser
    self._get_translated_date(), settings=self._settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/conf.py", line 81, in wrapper
    return f(*args, **kwargs)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/date_parser.py", line 26, in parse
    date_obj, period = parse(date_string, settings=settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/parser.py", line 70, in parse
    raise exceptions.pop(-1)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/parser.py", line 64, in parse
    res = parser(datestring, settings)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/parser.py", line 442, in parse
    dateobj = po._correct_for_time_frame(dateobj)
  File "/home/goblin/.local/share/virtualenvs/rtv-downloader-2I2VannR/lib/python3.6/site-packages/dateparser/parser.py", line 387, in _correct_for_time_frame
    if self.now < dateobj.replace(tzinfo=None):
TypeError: can't compare offset-naive and offset-aware datetimes

Changing line 387 in dateparser/parser.py to if self.now.replace(tzinfo=None) < dateobj: helps (the video gets downloaded), but that's probably not the right solution.

@danielsnider
Copy link

danielsnider commented Jun 10, 2019

Same fix worked for me:

Changing line 387 in dateparser/parser.py to if self.now.replace(tzinfo=None) < dateobj: helps (the video gets downloaded), but that's probably not the right solution.

Thank you @goblin!

@jonathanbessette
Copy link

I received the same error using search_dates.

I changed two lines (396 and 404) from "if self.now < dateobj:" to "if self.now.replace(tzinfo=None) < dateobj:" in parser.py

Also, took me a while but to find the file tree where I installed dateparser, I used "pip show dateparser" and opened the parser.py script by following my file location that way.

This helped with using the feature search_dates from dateparser.search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants