Archived

This topic is now archived and is closed to further replies.

twistedfall

uTorrent WebUI command line utility and library for Python 3

Recommended Posts

Fixed torrent sorting broken by previous changes and improved recheck logic, it now automatically stops torrents before recheck and starts (if required) after.

Share this post


Link to post
Share on other sites

Version supporting newer builds of µTorrent Linux server was just committed. Please note that older builds are no longer supported. Also there were API changes because of that.

Share this post


Link to post
Share on other sites

Thank you for the script. I am seeing a problem when using the script.

command:

utorrentctl.py --settings

exception:

Traceback (most recent call last):
File "C:\heap\deploy\twistedfall-utorrentctl-53c39f3\utorrentctl.py", line 664, in _get_data
resp = self.getresponse()
File "C:\Python31\lib\http\client.py", line 1033, in getresponse
response.begin()
File "C:\Python31\lib\http\client.py", line 347, in begin
version, status, reason = self._read_status()
File "C:\Python31\lib\http\client.py", line 303, in _read_status
line = str(self.fp.readline(), "iso-8859-1")
File "C:\Python31\lib\socket.py", line 228, in readinto
return self._sock.recv_into(
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\heap\deploy\twistedfall-utorrentctl-53c39f3\utorrentctl.py", line 1306, in <module>
utorrent = uTorrentConnection( opts.host, opts.user, opts.password ).utorrent()
File "C:\heap\deploy\twistedfall-utorrentctl-53c39f3\utorrentctl.py", line 765, in utorrent
ver = Version( self.do_action( "getversion", retry = False ) )
File "C:\heap\deploy\twistedfall-utorrentctl-53c39f3\utorrentctl.py", line 757, in do_action
res = self._get_data( self._action( action, params, params_str ), data = data, retry = retry, save_buffer = save_buffer, progr
ess_cb = progress_cb )
File "C:\heap\deploy\twistedfall-utorrentctl-53c39f3\utorrentctl.py", line 699, in _get_data
elif e.args[0] == errno.ECONNREFUSED:
AttributeError: 'int' object has no attribute 'args'

I have WebUI and uTorrent up and running on my host. Can you please help me get around this?

Oh and I'm trying this on Windows Server 2003. Thanks!

Share this post


Link to post
Share on other sites

> socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

It seems that you don't have access to the remote host running uTorrent. Can you connect to it via web browser? If yes, did you specify connection parameters of utorrentctl correctly? Did you use config.py file or pass arguments via command line?

Share this post


Link to post
Share on other sites

Yes. I used config.py to pass arguments. and I can connect to the WebUI via browser for the client. However, when executing from command line I get the exception repeatedly. Any suggestions?

Thanks!

Share this post


Link to post
Share on other sites

Could you show me your config file? (hostname and password hidden of course :) )

Like that:

#!/usr/bin/env python3

# default username and password

utorrentcfg = {

'host' : '<hostname>:16006',

'login' : 'utorrent',

'password' : '<password>'

}

Share this post


Link to post
Share on other sites

Thanks for sharing your work with everyone.

I'm experiencing exactly the same issue as monica2587, and this issue seems to be related to accessing a machine from the same host utorrent is running on.

Here is my error:

C:\utorrentctl>utorrentctl.py -l -c
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 668, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 308, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python32\lib\socket.py", line 273, in readinto
return self._sock.recv_into(
socket.error: [Errno 10054] An existing connection was forcibly closed by the re
mote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1311, in <module>
utorrent = uTorrentConnection( opts.host, opts.user, opts.password ).utorren
t()
File "C:\utorrentctl\utorrentctl.py", line 769, in utorrent
ver = Version( self.do_action( "getversion", retry = False ) )
File "C:\utorrentctl\utorrentctl.py", line 761, in do_action
res = self._get_data( self._action( action, params, params_str ), data = dat
a, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 703, in _get_data
elif e.args[0] == errno.ECONNREFUSED:
AttributeError: 'int' object has no attribute 'args'

C:\utorrentctl>

Config.py

#!/usr/bin/env python3

# default username and password
utorrentcfg = {
'host' : 'localhost:3391',
'login' : 'user',
'password' : 'nopass'
}

Telnet localhost 3391 connects and gives me a blinking cursor, although it can take 3-4 seconds before the cursor pops up.

I've tried localhost:3391, machinename:3391, 127.0.0.1:3391. I've tried using the config.py, I've tried using the command line, it makes no difference.

C:\utorrentctl>utorrentctl.py -H localhost:3391 -U user -P nopass -c -l
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 668, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 308, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python32\lib\socket.py", line 273, in readinto
return self._sock.recv_into(
socket.error: [Errno 10054] An existing connection was forcibly closed by the re
mote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1311, in <module>
utorrent = uTorrentConnection( opts.host, opts.user, opts.password ).utorren
t()
File "C:\utorrentctl\utorrentctl.py", line 769, in utorrent
ver = Version( self.do_action( "getversion", retry = False ) )
File "C:\utorrentctl\utorrentctl.py", line 761, in do_action
res = self._get_data( self._action( action, params, params_str ), data = dat
a, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 703, in _get_data
elif e.args[0] == errno.ECONNREFUSED:
AttributeError: 'int' object has no attribute 'args'

C:\utorrentctl>

I've allowed python.exe and pythonw.exe through the firewall. (didn't work) I disabled windows firewall completely. (didn't work)

I turned webui.auth token on and off, it didn't help.

The script works from a different pc on my network. (A server 2003 SP1 machine with 32bit python)

Machine that doesn't work with script, which is also running the uTorrent I want to connect to:

OS: Server 2008 R2 SP1 (x64)

Python: 3.2 x64 bit (latest)

uTorrent: 2.2.23703

Share this post


Link to post
Share on other sites

It seems to have improved access from the remote machine, esp using <IP>:<PORT>. I just noticed a bit ago that it was only successfully working remotely maybe 1/5 times. Now it seems to be perhaps 4/5 times. Here is a sequence of events from the remote machine..it works, then doesn't, then does, then doesn't...


C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
DAF31BC1F60FB151386816F8F68C8176B51786EE Downloading 26.8% 228.91GiB D: 1.60MiB/s U: 2.92kiB/s 0.00 2/2 eta: 4d 8h MyTorrentName
Properties:
label = MyLabel
dht = -1
dlrate = 0
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
pex = -1
seed_override = 0
seed_ratio = 1050
seed_time = 900
superseed = 0
trackers:
http://MyTracker
ulrate = 0
Read-only:
availability = 258129
dl_remain = 179823525888
dl_speed = 1681474
downloaded = 65963068755
eta = 375966
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
name = MyTorrentName
peers_connected = 24
peers_total = 51
progress = 26.8
queue_order = 1
ratio = 0.003
seeds_connected = 2
seeds_total = 2
size = 245785120083
status = Downloading
ul_speed = 2993
uploaded = 231915520

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1489, in <module>
tors = utorrent.torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 1003, in torrent_list
res = self._fetch_torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 995, in _fetch_torrent_list
out = self.do_action( "list" )
File "C:\utorrentctl\utorrentctl.py", line 969, in do_action
return self._connection.do_action( action = action, params = params, params_str = params_str, data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 782, in do_action
res = self._get_data( self._action( action, params, params_str ), data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 729, in _get_data
raise e
File "C:\utorrentctl\utorrentctl.py", line 680, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 316, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
DAF31BC1F60FB151386816F8F68C8176B51786EE Downloading 26.8% 228.91GiB D: 1.66MiB/s U: 3.09kiB/s 0.00 2/2 eta: 4d 7h MyTorrentName
Properties:
label = MyLabel
dht = -1
dlrate = 0
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
pex = -1
seed_override = 0
seed_ratio = 1050
seed_time = 900
superseed = 0
trackers:
http://mytracker
ulrate = 0
Read-only:
availability = 258131
dl_remain = 179790905344
dl_speed = 1736603
downloaded = 65995689299
eta = 373643
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
name = MyTorrentName
peers_connected = 24
peers_total = 51
progress = 26.8
queue_order = 1
ratio = 0.003
seeds_connected = 2
seeds_total = 2
size = 245785120083
status = Downloading
ul_speed = 3164
uploaded = 231948288

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1489, in <module>
tors = utorrent.torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 1004, in torrent_list
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 1004, in <dictcomp>
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 283, in __init__
self.fill( torrent )
File "C:\utorrentctl\utorrentctl.py", line 362, in fill
self.completed_on, self._unk_str, self.download_dir = torrent[19:27]
ValueError: need more than 0 values to unpack

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1489, in <module>
tors = utorrent.torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 1003, in torrent_list
res = self._fetch_torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 995, in _fetch_torrent_list
out = self.do_action( "list" )
File "C:\utorrentctl\utorrentctl.py", line 969, in do_action
return self._connection.do_action( action = action, params = params, params_str = params_str, data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 782, in do_action
res = self._get_data( self._action( action, params, params_str ), data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 729, in _get_data
raise e
File "C:\utorrentctl\utorrentctl.py", line 680, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 316, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1489, in <module>
tors = utorrent.torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 1003, in torrent_list
res = self._fetch_torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 995, in _fetch_torrent_list
out = self.do_action( "list" )
File "C:\utorrentctl\utorrentctl.py", line 969, in do_action
return self._connection.do_action( action = action, params = params, params_str = params_str, data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 782, in do_action
res = self._get_data( self._action( action, params, params_str ), data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 729, in _get_data
raise e
File "C:\utorrentctl\utorrentctl.py", line 680, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 316, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''

C:\utorrentctl>utorrentctl.py --dump DAF31BC1F60FB151386816F8F68C8176B51786EE
DAF31BC1F60FB151386816F8F68C8176B51786EE Downloading 27.4% 228.91GiB D: 1.90MiB/s U: 6.41kiB/s 0.00 2/2 eta: 1w 5d MyTorrentName
Properties:
label = MyLabel
dht = -1
dlrate = 0
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
pex = -1
seed_override = 0
seed_ratio = 1050
seed_time = 900
superseed = 0
trackers:
MyTrackerName
ulrate = 0
Read-only:
availability = 259831
dl_remain = 178421628928
dl_speed = 1991172
downloaded = 67364965715
eta = 1058420
hash = DAF31BC1F60FB151386816F8F68C8176B51786EE
name = MyTorrentName
peers_connected = 29
peers_total = 59
progress = 27.4
queue_order = 1
ratio = 0.003
seeds_connected = 2
seeds_total = 2
size = 245785120083
status = Downloading
ul_speed = 6562
uploaded = 233537536

The error message has changed when running the script from the local machine, but I still can't get it to work.



C:\utorrentctl>utorrentctl.py -l -c
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1341, in <module>
for h, t in sorted( utorrent.torrent_list().items(), key = lambda x: getattr( x[1], opts.sort_field ), reverse = opts.sort_desc ):
File "C:\utorrentctl\utorrentctl.py", line 1004, in torrent_list
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 1004, in <dictcomp>
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 283, in __init__
self.fill( torrent )
File "C:\utorrentctl\utorrentctl.py", line 362, in fill
self.completed_on, self._unk_str, self.download_dir = torrent[19:27]
ValueError: need more than 0 values to unpack

C:\utorrentctl>utorrentctl.py -l -c
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1341, in <module>
for h, t in sorted( utorrent.torrent_list().items(), key = lambda x: getattr( x[1], opts.sort_field ), reverse = opts.sort_desc ):
File "C:\utorrentctl\utorrentctl.py", line 1003, in torrent_list
res = self._fetch_torrent_list()
File "C:\utorrentctl\utorrentctl.py", line 995, in _fetch_torrent_list
out = self.do_action( "list" )
File "C:\utorrentctl\utorrentctl.py", line 969, in do_action
return self._connection.do_action( action = action, params = params, params_str = params_str, data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 782, in do_action
res = self._get_data( self._action( action, params, params_str ), data = data, retry = retry, save_buffer = save_buffer, progress_cb = progress_cb )
File "C:\utorrentctl\utorrentctl.py", line 722, in _get_data
raise e
File "C:\utorrentctl\utorrentctl.py", line 680, in _get_data
resp = self.getresponse()
File "C:\Python32\lib\http\client.py", line 1046, in getresponse
response.begin()
File "C:\Python32\lib\http\client.py", line 346, in begin
version, status, reason = self._read_status()
File "C:\Python32\lib\http\client.py", line 308, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python32\lib\socket.py", line 273, in readinto
return self._sock.recv_into(
socket.error: [Errno 10053] An established connection was aborted by the software in your host machine

Share this post


Link to post
Share on other sites

Tried the new version, this time it doesn't work on either 2003 remotely or 2008 locally, at all. But, I only get 1 error and it's the same error on both machines, so I guess that's positive :)

Here is the error now. It never changes no matter what I do.


C:\utorrentctl>utorrentctl.py -l -c
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1341, in <module>
for h, t in sorted( utorrent.torrent_list().items(), key = lambda x: getattr( x[1], opts.sort_field ), reverse = opts.sort_desc ):
File "C:\utorrentctl\utorrentctl.py", line 1004, in torrent_list
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 1004, in <dictcomp>
out = { h : self._TorrentClass( self, t ) for h, t in self._torrent_cache.items() }
File "C:\utorrentctl\utorrentctl.py", line 283, in __init__
self.fill( torrent )
File "C:\utorrentctl\utorrentctl.py", line 362, in fill
self.completed_on, self._unk_str, self.download_dir = torrent[19:27]
ValueError: need more than 0 values to unpack

Share this post


Link to post
Share on other sites

More good news, it seems the --server-version flag is working well 100% of the time, from either 2008 local or 2003 remote. So that eliminates a lot of possible issues.


C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

C:\utorrentctl>utorrentctl.py --server-version
BTWebClient/3000(23703) /UT3000 desktop v3.0.0.23703, engine v23703, ui v23703

Also --settings returns a different error.


C:\utorrentctl>utorrentctl.py --settings
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1378, in <module>
for i in sorted( utorrent.settings_get().items() ):
File "C:\utorrentctl\utorrentctl.py", line 1178, in settings_get
for name, type, value, attrs in res["settings"]:
ValueError: need more than 3 values to unpack

C:\utorrentctl>utorrentctl.py --settings
Traceback (most recent call last):
File "C:\utorrentctl\utorrentctl.py", line 1378, in <module>
for i in sorted( utorrent.settings_get().items() ):
File "C:\utorrentctl\utorrentctl.py", line 1178, in settings_get
for name, type, value, attrs in res["settings"]:
ValueError: need more than 3 values to unpack

Share this post


Link to post
Share on other sites

Yup, that's good news :) The connection problems are gone and we are now facing only server response format errors. That's something I can debug locally. According to the server-version response you are using µTorrent Falcon, am I right? If yes, then please, first make sure you downloaded and installed the latest version from http://user.utorrent.com/labs/get-falcon . Meanwhile I will install it locally to see what is wrong.

Share this post


Link to post
Share on other sites

Download the latest version. It should work at last. Also I added the ability to override server API version. So you could also try running utorrentctl with --server=desktop (see help for all available values). Specifying this option completely disables µTorrent API version auto-detection so if chosen incorrectly may produce erratic results. Actually this is what happened in your case. My utility was incorrectly identifying your µTorrent as Falcon.

Share this post


Link to post
Share on other sites

Doh, I didn't even notice that it reported version 3.0 and I'm actually using 2.2. Glad you figured that out :)

I got the latest, and as long as I force server=desktop it works great. Thank you so much for your work.

With this working, I should be able to create a vbs script that calls your script on every state change of a torrent, pass my script the hash id, pass it to yours, then pull the tracker out with yours, do some tracker=label logic with mine, then assign a label based on the tracker with yours...and voila, auto labels!

Thanks again

Share this post


Link to post
Share on other sites
:)) You are welcome. I'll try to work out some more robust version detection based on build number, but apparently there is no logic in assigning those...

Share this post


Link to post
Share on other sites

It's just the SVN revision number... and the repository is shared by all versions. Having the "build" key made sense in the past, when there was only one branch being tested at any given time. Doesn't work quite so well now with 3+ branches being tested simultaneously :/

The only way I've managed to reliably differentiate between 2.2 and 3.0 is to check action=getsettings to see if webui.uconnect_enable is defined. If so, then it's 3.0; if not, then it's 2.2 (or more precisely, anything older, but who's counting those really?).

Share this post


Link to post
Share on other sites

Thanks, that helped! I have implemented the detection of the aforementioned setting. So the auto-detection should be reliable now. Also, for those affected, I have renamed --server option into --api (but it shouldn't be required now anyway).

Share this post


Link to post
Share on other sites

I"ve downloaded and trying to run from F14 and get the following error...

[root@home home]# python utorrentctl.py --help
File "utorrentctl.py", line 1280
print_orig = print
^
SyntaxError: invalid syntax

Any assistance would be appreciated..

jbmia

Share this post


Link to post
Share on other sites