Perl script accessing WEBUI problem (Page 1) / Web API / µTorrent Community Forums
 

#1 2012-02-18 10:34:27

mario595
Member

Perl script accessing WEBUI problem

I am trying to write a Perl script that will pause all Torrents. I am just getting started and cannot get a list of Torrents returned. The script is using the Net::uTorrent module: http://cpan.uwinnipeg.ca/htdocs/Net-uTo … rrent.html

This is the script so far:

 
# uTorrent_pause.pl
#
# Perl script to pause all uTorrent downloads...
#
use strict;
use warnings;
use Net::uTorrent;

my $utorrent = Net::uTorrent->new (
				   hostname	=>	'localhost',
				   port		=>	'26693',
				   user		=>	'admin',
				   pass		=>	'admin',
				   );
die unless $utorrent->login_success;

my $tors = $utorrent->torrents ;

The call  $utorrent->torrents is failing. The exact error message:

malformed JSON string, neither array, object, number, string or atom, at character offset 2 (before "invalid request") at C:/Perl64/site/lib/Net/uTorrent.pm line 82.

The code around line 82:

sub torrents {
		my ($class,%args) = @_;
		my %params = (
			        list	=>	1,	      
			     );
		%params = (%params,%args); #Add optional cache id from argument.
		my @args = qw();
		push @args,\%params;
		my $json_text = api_query_result(@args);
LINE 82 ->               my $decoded_json = $json->decode($json_text);

I was able to do some debugging and $json_text has the string "invalid" in it. I did some more debugging and I am getting write failed:Unknown error code: 500 errors when it is making HTTP call to get the list. I can't tell you exactly where the error is generated because the flow of instructions bounces around many modules.

This is a pretty basic call to get the hashref list of torrents. I was wondering if maybe there is a setting somewhere that is causing this error. I tried running the script from an elevated DOS command prompt but that didn't affect the problem. Running this on Windows 7 64bit and IE9. Can anybody steer me in the right direction?

Offline

#2 2012-02-18 12:16:55

DreadWingKnight
I never claimed to be nice.

Re: Perl script accessing WEBUI problem

moving to the webui section of the forums.


FAQ and Search - Use them.
If guides ask for info, provide it before I have to ask for it.

Offline

#3 2012-02-24 11:04:41

mcmanuss8
Member

Re: Perl script accessing WEBUI problem

The issue is the uTorrent library doesn't deal with cookies. (See http://forum.utorrent.com/viewtopic.php?id=111446). This bit me on the upgrade to 3.1.2.

Fix is pretty simple, a 2 liner. I'm running Linux, so my fix is quick and dirty for that. I'm sure a more elegant solution would find a better file location for the cookie jar, but I'm lazy. Here's what I added:

Line 17: use HTTP::Cookies;
Line 51 (after $ua->credentials...):      $ua->cookie_jar(HTTP::Cookies::Netscape->new('file' => '/tmp/utorrent_cookies' ));

And that did the trick.

Offline

#4 2012-02-25 16:21:23

mario595
Member

Re: Perl script accessing WEBUI problem

I am not sure what is going on here but you are corrrect sir.
I had to modify it slightly to get it to work with Internet Explorer.

For those interested:

use HTTP::Cookies::Microsoft;
use Win32::TieRegistry(Delimiter => "/");
my $cookies_dir= $Registry->
      {"CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies"};

$ua->cookie_jar(HTTP::Cookies::Microsoft->new(file => "$cookies_dir\\index.dat", 'delayload' => 1,));

Offline

Board footer

Powered by FluxBB

©2013 BitTorrent, Inc. µTorrent is a trademark of BitTorrent, Inc.