1. David Larlet
  2. django-storages
  3. Issues

Issues

Issue #115 invalid

s3boto: Could not parse date string: 2012-03-30T16:43:39.000Z

Anonymous created an issue

The change [[http://code.larlet.fr/django-storages/changeset/16b149845a2d|16b149845a2d]] seems to have introduced a regression... I am now getting the following error when trying to use s3boto:

File "env/local/lib/python2.7/site-packages/staticfiles/management/commands/collectstatic.py", line 187, in delete_file self.storage.modified_time(prefixed_path) File "env/local/lib/python2.7/site-packages/storages/backends/s3boto.py", line 334, in modified_time return _parse_datestring(entry.last_modified) File "env/local/lib/python2.7/site-packages/storages/backends/s3boto.py", line 119, in _parse_datestring raise ValueError("Could not parse date string: " + dstr) ValueError: Could not parse date string: 2012-03-30T16:43:39.000Z

If I revert to revision [[http://code.larlet.fr/django-storages/changeset/3a53e65bf4cc|3a53e65bf4cc]], this bug disappears.

Comments (16)

  1. Ian Lewis

    Interesting, When I tested it, the modified time from S3 came back as a string that looks like "Wed, 12 Oct 2009 17:50:00 GMT". The error you're getting seems to indicate that S3 just gives you any date format it damn well pleases. Hmm. That makes it very hard to parse dates without a flexible library like dateutil since I really don't know what format it will be. If S3 changes slightly it could break the s3boto storage so that's a bit scary.

  2. Anonymous

    Shouldn't boto.utils.parse_ts() work? If you use that, you can rely on boto to get the date formatting done correctly.

  3. darkness51

    def _parse_datestring(dstr): utc_datetime = parse_ts(dstr)

    # Convert the UTC datetime object to local time.
    return datetime.fromtimestamp(calendar.timegm(utc_datetime.timetuple()))
    
  4. Chris Lambacher

    Dates can come back in either format. I put this at the top of the _parse_datestring function:

    try:
        utc_datetime = utc_datetime = parse_ts(dstr)
        return datetime.fromtimestamp(calendar.timegm(utc_datetime.timetuple()))
    except ValueError:
        pass
    
  5. Log in to comment