Skip Menu |

This queue is for tickets about the URI-Amazon-APA CPAN distribution.

Report information
The Basics
Id: 48995
Status: resolved
Priority: 0/
Queue: URI-Amazon-APA

People
Owner: Nobody in particular
Requestors: cslemmen [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Time stamp bug in URI::Amazon::APA ver. 0.2
Date: Tue, 25 Aug 2009 09:51:21 -0700 (PDT)
To: bug-URI-Amazon-APA [...] rt.cpan.org
From: Stuart Lemmen <cslemmen [...] yahoo.com>
Dist. name: URI::Amazon::APA ver. 0.2 Perl ver.: This is perl, v5.8.8 built for MSWin32-x86-multi-thread O/S: Win XP Pro 5.1 Greetings, I encountered several errors when attempting to make an "AWSECommerceService" request to Amazon Web Services that came down to this line in your URI::Amazon::APA package: $q{Timestamp} ||= strftime( "%Y-%m-%dT%TZ", gmtime() );    # 2009-01-01T12:00:00Z The first error was: <?xml version="1.0"?><ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2009-01-01/"><Error><Code>InvalidParameterValue</Code><Message>Value 2009-08-25TZ for parameter Timestamp is invalid. Reason: Must be in ISO8601 format.</Message></Error><RequestID>a9b655f2-36b8-4ead-a49c-97d69efd069c</RequestID></ItemLookupErrorResponse> I fixed that by creating a time stamp in in the correct format (and in the future, otherwise Amazon complained about it the request being too old!) by using the "DateTime" package's "iso8601" method. To get this to work with your code I added a third key to the argument hash, "time_stamp" that I fill by creating a date with DateTime (in the future by one day - that may be overkill but it works) and then using the "iso8601" method. Here's my code for that: my $today = new DateTime(year => get_current_year(),                          month => localtime->mon() + 1,                          day => localtime->mday() + 1,    # Must be in the future!                          hour => localtime->hour(),                          minute => localtime->min(),                          second => localtime->sec(),                          time_zone => "America/Chicago"); And the call to your package's method: $u->sign(key => 'my_access_key', secret => 'my_secret_key', time_stamp => $today->iso8601); The line above in your code now looks lie: $q{Timestamp} = $arg{time_stamp};    # 2009-01-01T12:00:00Z I'm sure there's a more elegant/safer way of doing this but this works for me at the present - IE Amazon is happy and returning the right data and no errors :) -Stuart Lemmen
'Value 2009-08-25TZ for parameter Timestamp is invalid'. Hmm. Looks more like strftime() is buggy for not parsing %TZ as '%T' . 'Z'. Tell me if the patch below fixes the problem. diff -u -r0.2 lib/URI/Amazon/APA.pm --- lib/URI/Amazon/APA.pm 2009/05/22 19:31:05 0.2 +++ lib/URI/Amazon/APA.pm 2009/10/19 09:20:52 @@ -22,9 +22,13 @@ my %eq = map { split /=/, $_ } split /&/, $self->query(); my %q = map { $_ => decode_utf8( uri_unescape( $eq{$_} ) ) } keys %eq; $q{AWSAccessKeyId} = $arg{key}; - $q{Timestamp} ||= - strftime( "%Y-%m-%dT%TZ", gmtime() ); # 2009-01-01T12:00:00Z - $q{Version} ||= '2009-01-01'; + $q{Timestamp} ||= do { + my ( $ss, $mm, $hh, $dd, $mo, $yy ) = gmtime(); + join '', + sprintf( '%04d-%02d-%02d', $yy + 1900, $mo + 1, $dd ), 'T', + sprintf( '%02d:%02d:%02d', $hh, $mm, $ss ), 'Z'; + }; + $q{Version} ||= '2009-01-01'; my $sq = join '&', map { $_ . '=' . uri_escape_utf8( $q{$_} ) } sort keys %q; my $tosign = join "\n", 'GET', $self->host, $self->path, $sq; Dan the Maintainer Thereof On Tue Aug 25 12:51:55 2009, cslemmen@yahoo.com wrote: Show quoted text
> Dist. name: URI::Amazon::APA ver. 0.2 > Perl ver.: This is perl, v5.8.8 built for MSWin32-x86-multi-thread > O/S: Win XP Pro 5.1 > > Greetings, I encountered several errors when attempting to make an > "AWSECommerceService" request to Amazon Web Services that came down > to this line in your URI::Amazon::APA package: > > $q{Timestamp} ||= strftime( "%Y-%m-%dT%TZ", gmtime() );    # 2009-01- > 01T12:00:00Z > > The first error was: > > <?xml version="1.0"?><ItemLookupErrorResponse > xmlns="http://ecs.amazonaws.com/doc/2009-01- > 01/"><Error><Code>InvalidParameterValue</Code><Message>Value 2009- > 08-25TZ for parameter Timestamp is invalid. Reason: Must be in > ISO8601 format.</Message></Error><RequestID>a9b655f2-36b8-4ead- > a49c-97d69efd069c</RequestID></ItemLookupErrorResponse> > > I fixed that by creating a time stamp in in the correct format (and in > the future, otherwise Amazon complained about it the request being > too old!) by using the "DateTime" package's "iso8601" method. > > To get this to work with your code I added a third key to the argument > hash, "time_stamp" that I fill by creating a date with DateTime (in > the future by one day - that may be overkill but it works) and then > using the "iso8601" method. Here's my code for that: > > my $today = new DateTime(year => get_current_year(), >                          month => localtime->mon() + 1, >                          day => localtime->mday() + 1,    # Must be in > the future! >                          hour => localtime->hour(), >                          minute => localtime->min(), >                          second => localtime->sec(), >                          time_zone => "America/Chicago"); > > And the call to your package's method: > > $u->sign(key => 'my_access_key', secret => 'my_secret_key', time_stamp > => $today->iso8601); > > The line above in your code now looks lie: > > $q{Timestamp} = $arg{time_stamp};    # 2009-01-01T12:00:00Z > > I'm sure there's a more elegant/safer way of doing this but this works > for me at the present - IE Amazon is happy and returning the right > data and no errors :) > > -Stuart Lemmen > > >