Signed Url is working after the expiration date Cloud Storage python
Question:
I have found this question that seems dead so i will add more context.
i am using the python google-cloud-storage sdk to generate signed urls using blob.generated_signed_url()
.
Here is the full method i use :
blob.generate_signed_url(expiration=datetime.now() + timedelta(minutes=1), version="v4")
I live in France so my Timezone is +1h from datetime.now().
The generated URL looks fine, i see the part of the expiration and the date : X-Goog-Date=20230318T191451Z&X-Goog-Expires=3659
But now it’s 20min after this delay and the doc is still available.
Note : I have also tried using timedelta(hours=1, minutes=1)
to simulate the France Timezone but it is still available also after 2mins of waiting.
What I am doing wrong ?
Answers:
From the documentation,
X-Goog-Expires
: The length of time the signed URL remained valid, measured in seconds from the value in X-Goog-Date
.
In your case, it’s 3659
that’s roughly an hour and not a minute. Try:
url = blob.generate_signed_url(
version="v4",
expiration=datetime.timedelta(minutes=1),
method="GET",
)
This should work irrespective of your timezone as it’s using a timedelta
instance so timedelta(hours=1, minutes=1)
would be 61 minutes. Timezone should be concern if you are using datetime
instance instead as mentioned in the API reference:
If a datetime instance is passed without an explicit tzinfo set, it will be assumed to be UTC.
I have found this question that seems dead so i will add more context.
i am using the python google-cloud-storage sdk to generate signed urls using blob.generated_signed_url()
.
Here is the full method i use :
blob.generate_signed_url(expiration=datetime.now() + timedelta(minutes=1), version="v4")
I live in France so my Timezone is +1h from datetime.now().
The generated URL looks fine, i see the part of the expiration and the date : X-Goog-Date=20230318T191451Z&X-Goog-Expires=3659
But now it’s 20min after this delay and the doc is still available.
Note : I have also tried using timedelta(hours=1, minutes=1)
to simulate the France Timezone but it is still available also after 2mins of waiting.
What I am doing wrong ?
From the documentation,
X-Goog-Expires
: The length of time the signed URL remained valid, measured in seconds from the value inX-Goog-Date
.
In your case, it’s 3659
that’s roughly an hour and not a minute. Try:
url = blob.generate_signed_url(
version="v4",
expiration=datetime.timedelta(minutes=1),
method="GET",
)
This should work irrespective of your timezone as it’s using a timedelta
instance so timedelta(hours=1, minutes=1)
would be 61 minutes. Timezone should be concern if you are using datetime
instance instead as mentioned in the API reference:
If a datetime instance is passed without an explicit tzinfo set, it will be assumed to be UTC.