Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: list index out of range #6

Closed
bobskiman opened this issue Jul 10, 2021 · 11 comments
Closed

IndexError: list index out of range #6

bobskiman opened this issue Jul 10, 2021 · 11 comments

Comments

@bobskiman
Copy link

bobskiman commented Jul 10, 2021

Hi, i'm getting this error when attempting to use the test function with torrent hash.
I'm using linuxserver/docker which has python3 installed. To get it running i had to change the "import urllib2" to "import urllib.request as urllib2" to actually run through the import stage of the script.

# python3 delugePush.py ec14426efba962e29adeb462e3c82140d88c55ff
Traceback (most recent call last):
  File "delugePush.py", line 127, in <module>
    getState(torrentHash, torrentName, RATIO_CHECK_DELAY, False)
  File "delugePush.py", line 100, in getState
    ratioIndex = lines[5].find('Ratio: ')
IndexError: list index out of range

Let me know if i can help in troubleshooting.

@bobskiman
Copy link
Author

bobskiman commented Jul 10, 2021

Edit: I did not have the proper version in the config file. (was set to default and i am using v2)

After changing this, here is the output im getting for a "Downloading" file

root@61ce073b93d6:/hostbin/deluge-dc-notif-master# python3 delugePush.py 729cbc58cbfaf3c4d3372b09616bc4f575d0bee5
Traceback (most recent call last):
  File "delugePush.py", line 127, in <module>
    getState(torrentHash, torrentName, RATIO_CHECK_DELAY, False)
  File "delugePush.py", line 73, in getState
    sendMessage("Added torrent!", torrentName, tracker)
  File "delugePush.py", line 43, in sendMessage
    response = urllib2.urlopen(req)
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 524, in open
    req = meth(req)
  File "/usr/lib/python3.6/urllib/request.py", line 1255, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

and here is for a completed file:

Traceback (most recent call last):
  File "delugePush.py", line 127, in <module>
    getState(torrentHash, torrentName, RATIO_CHECK_DELAY, False)
  File "delugePush.py", line 83, in getState
    sendMessage(message, torrentName, tracker, ratioValue)
  File "delugePush.py", line 43, in sendMessage
    response = urllib2.urlopen(req)
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 524, in open
    req = meth(req)
  File "/usr/lib/python3.6/urllib/request.py", line 1255, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

@ckcr4lyf
Copy link
Owner

I think this is mostly certainly due to python3, the script is intended for use with python2. I will make sure to add this to the README, for now there is no "quick fix", except that your python command default to python2 (2.7 probably).

Can you try running it locally with python instead of python3?

@bobskiman
Copy link
Author

bobskiman commented Jul 13, 2021 via email

@ckcr4lyf
Copy link
Owner

Not completely sure, but I do have a box with python3 on it I think. Will try and play around a bit tomorrow, see if I can make another version of the script for those who still use Deluge.

@frunkAF
Copy link
Contributor

frunkAF commented Nov 22, 2022

I am able to test succesfully but invoking the command automatically through the Execute plugin gives me the following issue...

11:37:56 [INFO ][deluge.pluginmanagerbase :189 ] Plugin Label enabled... 11:37:56 [INFO ][deluge.pluginmanagerbase :189 ] Plugin Execute enabled... 11:38:21 [INFO ][deluge.ui.web.json_api :733 ] Adding torrent from file ubuntu-22.10-desktop-amd64.iso.torrentwith options{'file_priorities': [1], 'add_paused': False, 'sequential_download': False, 'pre_allocate_storage': False, 'download_location': '/downloads', 'move_completed': False, 'move_completed_path': '/downloads', 'max_connections': 103, 'max_download_speed': -1, 'max_upload_slots': 13, 'max_upload_speed': -1, 'prioritize_first_last_pieces': False, 'seed_mode': False, 'super_seeding': False} 11:38:21 [INFO ][deluge.core.torrentmanager :673 ] Torrent ubuntu-22.10-desktop-amd64.iso from user "localclient" added 11:38:22 [WARNING ][deluge_execute.core :116 ] Command "/config/delugePush.py" failed with exit code 1 11:38:22 [WARNING ][deluge_execute.core :120 ] stderr: b'Traceback (most recent call last):\n File "/config/delugePush.py", line 128, in <module>\n getState(torrentHash, torrentName, RATIO_CHECK_DELAY, False)\n File "/config/delugePush.py", line 71, in getState\n tracker = lines[7][9:]\nIndexError: list index out of range\n

@ckcr4lyf
Copy link
Owner

@frunkAF can you confirm your versions of deluge-console , deluged and python?

@frunkAF
Copy link
Contributor

frunkAF commented Nov 23, 2022

@ckcr4lyf I use the docker container, linuxserver/deluge:latest. Here's the output of a version command

root@deluge:/# deluge-console -v
deluge-console 2.1.1
libtorrent: 2.0.8.0
Python: 3.10.8
OS: Linux

I got it working now.

I added a print(delugeConsoleResult) in the getState section and monitored the console on portainer. The result printed was a permissions issue accessing the /root/.config directory. I went into the container and just chmod -R 0777 to blanket allow and the script is running perfectly.

So to get it working...

  1. Modified the delugePush.py to import urlib.request for new Python (Merge Request)
  2. Modified line 16 in /usr/lib/python3.10/site-packages/deluge/ui/console/init.py to Console().start() within the container
  3. chmod -R 0777 /root within the docker container

@ckcr4lyf
Copy link
Owner

I would guess (1) is related to #8 (and valid), (3) is related to docker stuffs.

But part (2) is concerning, since it seems you need to modify deluge-console 's code (as per what you shared earlier - https://forum.deluge-torrent.org/viewtopic.php?p=235215#p235215)

I will try and see if I can address that by better detecting the values instead of relying on hardcoded indexes

@ckcr4lyf
Copy link
Owner

ckcr4lyf commented Nov 24, 2022

@frunkAF ok, I have confirmed the execution. Issue (2) does not affect this script, it will only print an extra line at the end:

$ python delugePush.py f5357853359f3a1c3f5484350f6f60af779a7b88
<Deferred at 0x7f9ff214e1d0 current result: None>

so the exit code error etc, is mostly likely a docker permission thing.

Can you "undo" your change to console/init.py and see if it still works? We could close this issue then.

My testing without modifying that file:
image

$ deluge-console -v
deluge-console 2.1.1
libtorrent: 2.0.8.0
Python: 3.10.8
OS: Linux Arch Linux rolling n/a

@frunkAF
Copy link
Contributor

frunkAF commented Nov 24, 2022

It worked!

It looks like the message is not an issue. It was strictly a permissions issue once the code was updated for python 3

@ckcr4lyf
Copy link
Owner

Awesome. I will close this issue for now, @bobskiman you can use the new delugePush3.py script for Python3 compatibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants