Skip Menu |
 

This queue is for tickets about the Net-Google-Calendar CPAN distribution.

Report information
The Basics
Id: 69824
Status: resolved
Priority: 0/
Queue: Net-Google-Calendar

People
Owner: PLYTLE [...] cpan.org
Requestors: peter_retep [...] gmx.de
Cc:
AdminCc:

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



Subject: 302 Moved Temporarily at /usr/local/share/perl/5.8.8/Net/Google/Calendar.pm line 619.
Date: Wed, 27 Jul 2011 09:44:07 +0200
To: bug-Net-Google-Calendar [...] rt.cpan.org
From: Peter Retep <peter_retep [...] gmx.de>
Download (untitled) / with headers
text/plain 2.1k
Hi Simon, I am not sure if there were some changes at Google side or if there is an issue with Net::Google::Calendar. I used Net::Google::Calendar for months without any problems, thanks for this amazing interface! Problems started at the start of June 2011: If I use private calendar URL with email and password login, I get following message on $cal->get_events after successfully receiving and deleting some events. 302 Moved Temporarily at /usr/local/share/perl/5.8.8/Net/Google/Calendar.pm line 619. This is example code to see what type of requests is used: $XML::Atom::ForceUnicode = 1; $XML::Atom::DefaultVersion = "1.0"; $cal = Net::Google::Calendar->new( url => 'http://www.google.com/calendar/feeds/xxx%40group.calendar.google.com/private-xxx/full' ); $cal->login($email, $password) ; for my $range (@ranges){ my @events=$cal->get_events(get_range_parameters($range)); for my $event(@events){ $cal->delete_entry($event); }; } sub get_range_parameter{ my $start=$range->{start}; my $end =$range->{end}; my $parameters={}; $parameters->{"start-min"} = $start->datetime; $parameters->{"recurrence-expansion-start"}= $start->datetime; $parameters->{"start-max"} = $end->datetime; $parameters->{"recurrence-expansion-end"}= $end->datetime; return $parameters; } This (slightly changed) workaround I found at http://cpanforum.com/posts/13346 before line 619 in Net::Google::Calendar if ($r->code == 302) { my $c=0; while(($c<10)&&($r->code == 302)){ print STDERR "warn: error 302" if ($c>0); my $location = $r->header('location'); my %params = ($self->{_auth}->auth_params('GET', $location), %opts); $r = $self->{_ua}->get($location, %params); $c++; } } but I am not sure if it fixes the root cause, sometimes I get 501's using it. my environment: Net::Google::Calendar 1.0 perl, v5.8.8 built for x86_64-linux-gnu-thread-multi Linux hostname 2.6.18-028stab070.14 #1 SMP Thu Nov 18 16:04:02 MSK 2010 x86_64 GNU/Linux Best Regards, Peter
From: darren.meyer [...] gmail.com
Download (untitled) / with headers
text/plain 2.6k
I have a patch for this, attached. Net/Google/Calendar.pm assumes that redirects are 302 and one-shot, but they can also be 301 and chained. The patch changes this behavior and still passes all tests (and I'm using my patched version in production). The patch is calculated against module version 1.0 On Wed Jul 27 03:44:20 2011, peter_retep@gmx.de wrote: Show quoted text
> Hi Simon, > > I am not sure if there were some changes at Google side or if there is > an issue with Net::Google::Calendar. > I used Net::Google::Calendar for months without any problems, thanks > for this amazing interface! > > Problems started at the start of June 2011: > If I use private calendar URL with email and password login, I get > following message on $cal->get_events after successfully receiving and > deleting some events. > > 302 Moved Temporarily at > /usr/local/share/perl/5.8.8/Net/Google/Calendar.pm line 619. > > This is example code to see what type of requests is used: > > $XML::Atom::ForceUnicode = 1; > $XML::Atom::DefaultVersion = "1.0"; > > $cal = Net::Google::Calendar->new( url => > 'http://www.google.com/calendar/feeds/xxx%40group.calendar.google.com/private- > xxx/full' ); > $cal->login($email, $password) ; > > for my $range (@ranges){ > my @events=$cal->get_events(get_range_parameters($range)); > for my $event(@events){ > $cal->delete_entry($event); > }; > } > > sub get_range_parameter{ > my $start=$range->{start}; > my $end =$range->{end}; > > my $parameters={}; > $parameters->{"start-min"} = $start->datetime; > $parameters->{"recurrence-expansion-start"}= $start->datetime; > $parameters->{"start-max"} = $end->datetime; > $parameters->{"recurrence-expansion-end"}= $end->datetime; > return $parameters; > } > > This (slightly changed) workaround I found at > http://cpanforum.com/posts/13346 > before line 619 in Net::Google::Calendar > > if ($r->code == 302) { > my $c=0; > while(($c<10)&&($r->code == 302)){ > print STDERR "warn: error 302" if ($c>0); > my $location = $r->header('location'); > my %params = ($self->{_auth}-
> >auth_params('GET', $location), %opts);
> $r = $self->{_ua}->get($location, %params); > $c++; > } > } > > but I am not sure if it fixes the root cause, sometimes I get 501's > using it. > > my environment: > Net::Google::Calendar 1.0 > perl, v5.8.8 built for x86_64-linux-gnu-thread-multi > Linux hostname 2.6.18-028stab070.14 #1 SMP Thu Nov 18 16:04:02 MSK > 2010 x86_64 GNU/Linux > > Best Regards, Peter >
Subject: 301.patch
Download 301.patch
text/x-diff 1008b
--- Calendar.pm 2010-07-19 20:59:12.000000000 -0500 +++ /Library/Perl/5.10.0/Net/Google/Calendar.pm 2011-10-11 16:24:36.000000000 -0500 @@ -610,7 +610,7 @@ my %params = ($self->{_auth}->auth_params('GET', $feed), %opts); my $r = $self->{_ua}->get("$feed", %params); - if ($r->code == 302) { + while ($r->code == 302 || $r->code == 301) { my $location = $r->header('location'); %params = ($self->{_auth}->auth_params('GET', $location), %opts); $r = $self->{_ua}->get($location, %params); @@ -767,7 +767,7 @@ #my $rq = HTTP::Request->new($method => $url, $h); my $r = $self->{_ua}->request( $rq ); $self->{_cookie_jar}->extract_cookies($r); - if (302 == $r->code) { + while (302 == $r->code || 301 == $r->code) { $url = $r->header('location'); my %args = URI->new($url)->query_form; $self->{_session_id} = $args{gsessionid};
From: darren.meyer [...] gmail.com
Download (untitled) / with headers
text/plain 519b
Based on some feedback, here's a revised patch; this fixes a bug in my patch and provides a configurable redirect through a new global $REDIRECT_MAX (set to 10 in this patch, which seems reasonable). Additionally, it seems that Google *did* make a server side change, using a 301 (permanently moved) instead of a 302 (temporarily moved) on one resource this module consumes. It might be worth tracing to see which resource and changing *that* value -- but even so, this patch is a good idea for future robustness.
Subject: 301-2.patch
Download 301-2.patch
text/x-diff 2.1k
--- Calendar.pm 2010-07-19 20:59:12.000000000 -0500 +++ /Library/Perl/5.10.0/Net/Google/Calendar.pm 2011-10-11 20:31:21.000000000 -0500 @@ -17,11 +17,13 @@ use URI::Escape; use Carp qw(confess); -use vars qw($VERSION $APP_NAME); +use vars qw($VERSION $APP_NAME $REDIRECT_MAX); $VERSION = "1.0"; $APP_NAME = $Net::Google::OAuth::APP_NAME = __PACKAGE__."-${VERSION}"; +$REDIRECT_MAX = 10; #Maximum number of redirects to allow + =head1 NAME Net::Google::Calendar - programmatic access to Google's Calendar API @@ -610,10 +612,14 @@ my %params = ($self->{_auth}->auth_params('GET', $feed), %opts); my $r = $self->{_ua}->get("$feed", %params); - if ($r->code == 302) { + my $redirect_tries = 0; + while ($r->code == 302 || $r->code == 301) { my $location = $r->header('location'); %params = ($self->{_auth}->auth_params('GET', $location), %opts); $r = $self->{_ua}->get($location, %params); + $redirect_tries++; + die "Too many redirects ($redirect_tries)" + if $redirect_tries > $REDIRECT_MAX; } die $r->status_line unless $r->is_success; @@ -760,19 +766,23 @@ - while (1) { + REQUEST: while (1) { my $rq = POST "$url", %params; $self->{_cookie_jar}->add_cookie_header($rq); #my $h = HTTP::Headers->new(%params); #my $rq = HTTP::Request->new($method => $url, $h); my $r = $self->{_ua}->request( $rq ); $self->{_cookie_jar}->extract_cookies($r); - if (302 == $r->code) { + my $redirect_tries = 0; + while (302 == $r->code || 301 == $r->code) { $url = $r->header('location'); my %args = URI->new($url)->query_form; $self->{_session_id} = $args{gsessionid}; - next; - } + $redirect_tries++; + die "Too many redirects ($redirect_tries)" + if $redirect_tries > $REDIRECT_MAX; + next REQUEST; + } #print $rq->as_string unless $params{'X-HTTP-Method-Override'} ; if (!$r->is_success) {
RT-Send-CC: darren.meyer [...] gmail.com
Download (untitled) / with headers
text/plain 129b
This should be fixed in 1.01 - thanks very much for the patch. Please confirm that it works for you and I'll close this ticket.
Subject: Re: [rt.cpan.org #69824] 302 Moved Temporarily at /usr/local/share/perl/5.8.8/Net/Google/Calendar.pm line 619.
Date: Sat, 14 Apr 2012 22:15:39 +0200
To: bug-Net-Google-Calendar [...] rt.cpan.org
From: Peter Retep <peter_retep [...] gmx.de>
Download (untitled) / with headers
text/plain 419b
Am 19.03.2012 19:05, schrieb Peter Lytle via RT: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=69824> > > This should be fixed in 1.01 - thanks very much for the patch. Please > confirm that it works for you and I'll close this ticket. >
Hi Peter, I upgraded to 1.01 and were able to succesfully delete and insert 222 events without fault! From my view the ticket can be closed. Thanks for fixing! BR, Peter


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.