![]() |
Error when running mktorrent subprocess command - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error when running mktorrent subprocess command (/thread-29656.html) |
Error when running mktorrent subprocess command - pythonnewbie138 - Sep-14-2020 Hi there, I can't figure out why my mktorrent subprocess command is failing. Any help in understanding why would be much appreciated. Here's my code: import os import subprocess target_file = "C:\\Users\\REMOVED\\python_apps\\my_progs\\test_folder\\test.test-test.mp4" temp_dest = "C:\\Users\\REMOVED\\python_apps\\my_progs" final_dest = os.path.join(temp_dest, "test_folder") print(final_dest) basename = os.path.basename(target_file) torrent_name = basename + ".torrent" print(torrent_name) filesize = float(os.path.getsize(target_file)) #print(filesize) filesize_gb = round(filesize / (1024 * 1024 * 1024), 3) #print(filesize_gb) if filesize_gb >= 16: piece_size = 24 elif filesize_gb >= 8 and filesize_gb < 16: piece_size = 23 elif filesize_gb >= 4 and filesize_gb < 8: piece_size = 22 elif filesize_gb >= 2 and filesize_gb < 4: piece_size = 21 elif filesize_gb >= 1 and filesize_gb < 2: piece_size = 20 elif filesize_gb >= 0.5 and filesize_gb < 1: piece_size = 19 elif filesize_gb >= 0.35 and filesize_gb < 0.5: piece_size = 18 elif filesize_gb >= 0.15 and filesize_gb < 0.35: piece_size = 17 elif filesize_gb >= 0.05 and filesize_gb < 0.15: piece_size = 16 elif filesize_gb <= 0.05: piece_size = 15 #print(piece_size) os.chdir(final_dest) subprocess.run('mktorrent', '-vp', '-s', 'HUH', '-l', piece_size, '-a', 'https://sometracker.org/announce.php', target_file, '-o', torrent_name, final_dest)I'm receiving this error: Here is the expected command and I tested in cmd with success.mktorrent -vp -s HUH -l 16 -a http://sometracker.org/announce.php test.test-test.mp4 -o test.test-test.mp4.torrent C:\Users\REMOVED\python_apps\my_progs\test_folder
RE: Error when running mktorrent subprocess command - bowlofred - Sep-14-2020 The first argument to subprocess.run is the list of arguments. You're not passing them as a list. The second argument (optional) is bufsize. Your second argument of '-vp' isn't an integer, so it complains about it at that point. #Incorrect subprocess.run('/bin/ls', 'myfile') #Correct subprocess.run(['bin/ls', 'myfile']) Also, you can't enter the elif sections unless you've failed the previous if/elifs. So for instance in the first elif, you already know that filesize must be < 16, so you don't have to check for it again. # Equivalent to above: if filesize_gb >= 16: piece_size = 24 elif filesize_gb >= 8: piece_size = 23 elif filesize_gb >= 4: piece_size = 22 elif filesize_gb >= 2: piece_size = 21 ... RE: Error when running mktorrent subprocess command - pythonnewbie138 - Sep-16-2020 Thanks for the response. To address the first part, I should be able to just add the brackets around the list of arguments, right? subprocess.run(['mktorrent', '-vp', '-s', 'HUH', '-l', piece_size, '-a', 'https://sometracker.org/announce.php', target_file, '-o', torrent_name, final_dest])With that change, I'm now receiving the following error: The only integer in the command is piece_size. Does this mean that there's an issue with the command argument order? I was hoping to avoid that by verifying the expected command worked in cmd.Your elif block suggestion is great. Thank you! RE: Error when running mktorrent subprocess command - micseydel - Sep-16-2020 (Sep-16-2020, 01:23 AM)pythonnewbie138 Wrote: The only integer in the command is piece_size. Does this mean that there's an issue with the command argument order?I came to a different hypothesis. Here's my test:
RE: Error when running mktorrent subprocess command - pythonnewbie138 - Sep-16-2020 Got it. Thanks! Simply changing piece_size to str(piece_size) fixed the problem. Definitely a facepalm moment haha.Thanks again to both of you! |