zmerlinz has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to use Flickr::API, but i am stuck behind a proxy. According to the documentation, Flickr::API is a subclass of LWP::UserAgent, so all of the various proxy, request limits, caching, etc are available. so i've tried setting the proxy with
require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->proxy('http', 'http://wwwcache.aber.ac.uk:8080/'); my $api = new Flickr::API({'key' => ''}); #There is an api key here! my $response = $api->execute_method('flickr.test.echo', { 'foo' => 'bar', 'baz' => 'quux', }); $ua->get($response);
but i get an error saying "Can't use a Flickr::API::Response object as a URI at /usr/share/perl5/HTTP/Request/Common.pm line 104" any ideas to why i am getting this ? full code is
#!/usr/bin/perl -w use Flickr::API; use Data::Dumper; require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->proxy('http', 'http://wwwcache.aber.ac.uk:8080/'); my $api = new Flickr::API({'key' => ''}); #there is normally an API ke +y here my $response = $api->execute_method('flickr.test.echo', { 'foo' => 'bar', 'baz' => 'quux', }); $ua->get($response); print "Success: $response->{success}\n"; print "Error code: $response->{error_code}\n"; print Dumper ($response);
Thank you for your time and help with this.

Replies are listed 'Best First'.
Re: Flickr::API and using a proxy
by fauxmarc (Initiate) on Dec 08, 2006 at 16:23 UTC
    instead of explicitly creating a separate LWP::UserAgent object, have you tried setting the proxy directly in the Flickr::API object like so?

    $api->proxy('http', 'http://wwwcache.aber.ac.uk:8080//');
      Exactly! The LWP object ($ua) had the proxy set, and then the code creates a completely different object in $api.

      This is why setting the proxy on $api works: Flickr::API is a subclass of LWP::UserAgent - so any method that LWP::UserAgent has, Flickr::API has (subject to Flickr::API overriding said method).

      To speak metaphorically, if LWP ::UserAgent was a quart of milk, and Flickr::API a quart of chocolate milk, you poured a glass of milk ($ua = LWP::UserAgent->new) and a glass of chocolate milk ($api = Flickr::API->new()), put a straw in the glass of milk (setting up the proxy on $ua), and then couldn't drink the chocolate milk because it didn't have a straw in it (you needed to call the proxy() method on $api).

      ah it make sense now :) because Flickr::API is a subclass of LWP::UserAgent, i can use the same switches, in this case proxy. Works a treat now thank you :)
Re: Flickr::API and using a proxy
by Corion (Patriarch) on Dec 08, 2006 at 14:14 UTC

    Have you tried without using a proxy? Does that change the error message?

    Your error is that $ua->get() expects an URI, while the $api-> calls return something else. While Perl does try to guess your intents, you cannot simply paste together the synopses of different modules and expect them to work.

      if i try with out the proxy, the dumper tells me that the connection was refused to www.flickr.com:80 so it does seem that it needs to be told about the proxy to get out to flickr.com

        Sorry - my first question was misleading then. Try print Dumper $response to see what actually gets returned from Flickr::API and then you should know why $ua->get() on that doesn't work.