Issues

Issue #56 wontfix

"AWS authentication requires a valid Date or x-amz-date header"

anentropic
created an issue

I was getting these errors, it seems to come from the web server clock being out of sync with Amazon's server.

For me it was related to Daylight Saving Time... our server is currently in BST (British Summer Time, GMT +1:00).

In S3.py, line 295 we have: {{{ headers['Date'] = time.strftime("%a, %d %b %Y %X GMT", time.gmtime()) }}}

time.gmtime() seems to give us the server time correctly adjusted to GMT, so maybe there is a bug in Amazon's GMT handling or something (that would be weird).

anyway, I can fix the error it seems by changing line #295 to: {{{ headers['Date'] = time.strftime("%a, %d %b %Y %X %Z", time.localtime()) }}}

I am a bit suspicious of my fix because it doesn't seem necessary, but it has worked for me.

Comments (9)

  1. Anonymous

    I saw the same issue. I am using Python 2.7 on Ubuntu 11.0.4, and django-storages-1.1.1

    I noticed that the date would sometimes include the AM/PM modifier. And sometimes it would be in military time.

    I changed line 295 to this: headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())

    Instead of %X, I use %H:%M:%S. That forces the datetime format to always use military time.

  2. diafygi

    In django-storages 1.1.3, I still had this issue. I fixed it by adding the following to line after line 135 in s3.py:

    'x-amz-date':time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()),
    

    I also had to add "import time" to the top of the file.

  3. Anonymous

    Another solution is to do it the way boto does.

    from email.Utils import formatdate          
    headers['Date'] = formatdate(usegmt=True)
    

    worked for me.

  4. Log in to comment