为什么Amazon S3签名URL在本地工作但不在生产服务器上?

时间:2012-06-30 07:29:24

标签: python django boto

我想知道是什么原因导致这个签名的URL方法在本地工作但不在真实服务器中工作?

在本地,它会生成一个在12秒内到期的URL,但在服务器中它会返回一个过期的URL吗?

def s3_signed_url(file_path):
    import boto
    s3conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    bucket = s3conn.get_bucket(BUCKET_NAME, validate=False)
    key = bucket.new_key(file_path)
    signed_url = key.generate_url(expires_in=12)
    return signed_url



@never_cache
def enjoy_the_show(request, movie_id):
    m = get_object_or_404(Movie, pk=movie_id)
    iOS = is_ios_device(request)
    if (iOS is True):
        movie_path = m.m3u8_url
        movie_path = movie_path.replace('https://s3.amazonaws.com/domain.com','')
        signed_url = s3_signed_url(movie_path)
        return render_to_response('movies/enjoy_show_iOS.html', {'signed_url':signed_url,'movie': m,'is_logged_in':is_logged_in(request)},context_instance=RequestContext(request))
    else:
        return render_to_response('movies/enjoy_show.html', {'movie': m,'is_logged_in':is_logged_in(request)},context_instance=RequestContext(request))

1 个答案:

答案 0 :(得分:2)

问题解决了。这是一个时区问题。 可以通过在两台服务器上正确配置时区和/或考虑时差来解决该问题。