clinton-hall / nzbToMedia

Provides NZB and Torrent postprocessing To CouchPotatoServer, SickBeard/SickRage, HeadPhones, Mylar and Gamez
GNU General Public License v3.0
672 stars 176 forks source link

PP Failure: no module named 'encode' #905

Closed mymindisempty closed 6 months ago

mymindisempty commented 8 years ago

Thanks for the work you do. It is much appreciated.

I've switched from sabnzbd to nzbget this weekend and I've set it up on my QNAP according to your instructions. All went pretty well and everything works until it gets to the postprocessing bit. I think it tries to call on something that doesn't exist (some kind of module) but I'm not a 100% sure what it is or what it is trying to do. Is it something I can skip in the settings? Or do I need to update Python - I think that's not the problem? The log in nzbget from bottom to top:

ERROR - Mon Dec 07 2015 06:04:18 Post-process-script nzbtomedia/nzbToMedia.py for DOWNLOAD-TITLE failed (terminated with unknown status) INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: ImportError: No module named encodings INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: File "/root/daily_build/4.2.0/Model/TS-119/../../SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/locale.py", line 15, in INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: import locale INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: File "/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/core/init.py", line 1, in INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: import core INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: File "/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py", line 503, in INFO - Mon Dec 07 2015 06:04:18 nzbToMedia: Traceback (most recent call last): INFO - Mon Dec 07 2015 06:04:18 Executing post-process-script nzbtomedia/nzbToMedia.py for DOWNLOAD-TITLE

Any pointers would be appreciated :).

clinton-hall commented 8 years ago

/root/daily_build/4.2.0/Model/TS-119/../../SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/locale.py

this is a weird version of python with next to no supported modules.

what version of NZBGet qpkg do you have? this seems to have a system path that points to this python first...

mymindisempty commented 8 years ago

Thank you for replying to me! I downloaded the Linux download on the official site (http://nzbget.net/download/) trying to get it up and running myself that way. Which was easier than I had anticipated. I found a QPKG on the official forum which I tried first but the config file blew up to over 4 MB because it kept repeating nzbtomedia and category settings (and the settings page of NZBtoMedia become unresponsive as a result). So I deleted that QPKG and installed the official download via the site and Terminal. Everything works apart from the post-process of renaming and moving (Delete Samples works, for example). I'm on a QNAP TS-119+ with the latest firmware. I was previously using SABnzbd but heard so many good things about NZBGET I figured I'd better try it :). Also, I wanted to try the latest nzbtomedia script :).

Any help is appreciated :).

clinton-hall commented 8 years ago

Odd, my NZBGet qpkg should work fine.

What version of Python qpkg do you have installed?

What you will need to do is add an export of PATH variable to the NZBGet start script so that the PATH lists the proper Python first.

E.g if Python (and python2) is at /opt/bin/python2 then you would use

export PATH=/opt/bin:$PATH

before NZBGet is launched.

mymindisempty commented 8 years ago

Ah I just realized it wasn't your QPKG but the one by the other guy. So that might be why the original didn't work. Will give this a go and report back. And otherwise I can always try your QPKG.

mymindisempty commented 8 years ago

OK. It may be the time of night over here but I'm not sure what to do next. I've found the Python path (which is simply in the .qpkg folder) which results in this line I have to add to the NZBGet start script: export PATH=/share/HDA_DATA/.qpkg/

But what do you mean by the NZBGet start script? Because I've added a piece of code that launches NZBGet at startup in a new autorun.sh file (there was no autorun.sh yet in my QNAP) and that works, so would I have to edit that again and add the PATH line above?

(it's Python 2.7.3 QPKG btw, which can be found in the App Center, I've even reinstalled it to see if it makes a difference. There's also a Python 3 QPKG which I didn't install. The weird thing is also that the original error you also mentioned has a different path and has a folder called python-2.7.5-cross etc in it).

clinton-hall commented 8 years ago

you need the path to the python binary...

so you need to add

export PATH=/share/HDA_DATA/.qpkg/python/bin:$PATH to the autorun.sh before NZBGet is started.

mymindisempty commented 8 years ago

Thank you. I've tried it by adding the line you said (see below)...

screenshot

But it doesn't make a difference, the process still goes wrong at the same point when I try to postprocess a finished download again:

screenshot2

I probably did something wrong with the export PART line since it didn't make a difference. Do I need the path to python.sh script? Because that's in the folder above 'bin'.

Once again, thank you for trying to help me.

clinton-hall commented 8 years ago

Python.sh is a start script, so that isn't needed for this.

Did you restart NZBGet after adding that export?

Have you tried running the script manually to see what version of Python does work?

mymindisempty commented 8 years ago

Yea, shut the whole NAS down even and then booted it up again. Twice to make sure. The autorun.sh worked, because it launched NZBGet and the line above is the PATH export...

I haven't tried running it manually. To be honest I'm not sure how to do that, still learning all this...

Just stumbled across this QNAP forum post from a user who has the same error, also after upgrading his QNAP firmware. http://forum.qnap.com/viewtopic.php?f=141&t=70719&p=509247#p509247 He hasn't reported back to say whether he has solved his problem though...
Another one here I think: http://forum.qnap.com/viewtopic.php?f=217&t=116322

EDIT: used 'find' to search for other versions of Python on my QNAP and this came up: /mnt/ext/opt/Python find: /proc/18163: No such file or directory find: /proc/18164: No such file or directory find: /proc/18181: No such file or directory /share/HDA_DATA/.qpkg/Python

Not sure if this makes a difference in any way. The final entry is the QPKG I installed and then there's the first result (and some weird lines in between?) which has 'bin', 'include' and 'lib' in it. The bin folder for example has this: 7 Dec 13 21:20 python -> python2 9 Dec 13 21:20 python2 -> python2.7 Nov 18 03:39 python2.7*

clinton-hall commented 8 years ago

ok, via ssh can you issue the following and post the output?

/mnt/ext/opt/Python/bin/python2 /share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py
/share/HDA_DATA/.qpkg/Python/bin/python2 /share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py
mymindisempty commented 8 years ago

the first line has this output:

Traceback (most recent call last):
  File "/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py", line 503, in <module>
    import core
  File "/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/core/__init__.py", line 1, in <module>
    import locale
  File "/root/daily_build/4.2.0/Model/TS-119/../../SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/locale.py", line 15, in <module>
ImportError: No module named encodings

The second line says this:

/share/HDA_DATA/.qpkg/Python/bin/python2: No such file or directory

Below the contents of the bin folder: screenshot3

So there's no python2 in there, only python and python2.7...

clinton-hall commented 8 years ago

Try

/share/HDA_DATA/.qpkg/Python/bin/python2.7 /share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py
mymindisempty commented 8 years ago

Well it did something:

[~] # /share/HDA_DATA/.qpkg/Python/bin/python2.7 /share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py  
[21:01:35] [INFO]::MAIN: Loading config from [/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/autoProcessMedia.cfg]
[21:01:35] [INFO]::MAIN: Checking database structure...
[21:01:35] [INFO]::MAIN: Checking if source needs an update
/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/libs/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/libs/requests/packages/urllib3/connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
[21:01:36] [ERROR]::MAIN: Unknown current version number, don't know if we should update or not
[21:01:36] [INFO]::MAIN: nzbToMedia Version:10.12 Branch:master (Linux 3.4.6)
[21:01:36] [WARNING]::MAIN: Failed to locate ffprobe. Video corruption detection disabled!
[21:01:36] [WARNING]::MAIN: Install ffmpeg with x264 support to enable this feature  ...
[21:01:37] [INFO]::MAIN: #########################################################
[21:01:37] [INFO]::MAIN: ## ..::[nzbToMedia.py]::.. ##
[21:01:37] [INFO]::MAIN: #########################################################
[21:01:37] [WARNING]::MAIN: Invalid number of arguments received from client, Switching to manual run mode ...
[21:01:37] [INFO]::MAIN: The /share/HDA_DATA/Download/nzbget/scripts/nzbtomedia/nzbToMedia.py script completed successfully.
[~] # 

It produces some errors but at least it SAYS it runs it succesfully at the end ;)?

clinton-hall commented 8 years ago

ok, in your NZBGet startup (autorun.sh)

ln -sf /share/HDA_DATA/.qpkg/Python/bin/python2.7 /share/HDA_DATA/.qpkg/Python/bin/python2
export PATH=/share/HDA_DATA/.qpkg/Python/bin:$PATH

then restart the NAS and enjoy.

mymindisempty commented 8 years ago

That totally worked! Thank you so so much for your support and patience. :)

clinton-hall commented 8 years ago

No worries. Let me know if you have any more dramas.

spaggi2 commented 8 years ago

I would like to Hijack this issue as I have exactly the same problem. Hope it is ok!

I've been struggeling all day with the same error message when postporcessing as the OP on my QNAP TS-412 after I upgraded to 4.2.

Error

I am using the nzbget QPKG

QPKG

NZB is being started normally via the qpkg config file which works fine

I did the same as you recommended adding the mentioned lines in autostart.sh (which I found using the official QNAP Wiki) as the following

ln -sf /share/HDA_DATA/.qpkg/Python/bin/python2.7 /share/HDA_DATA/.qpkg/Python/bin/python2
export PATH=/share/HDA_DATA/.qpkg/Python/bin:$PATH

The result is, that I can now execute the following command

python /share/HDA_DATA/Download/nzbget/scripts/nzbToMedia/nzbToMedia.py

Where I get the following result:

16:03:46|INFO    ====================
16:03:46|INFO    nzbToMedia V8.3
16:03:46|INFO    MAIN: Loading config from /share/HDA_DATA/Download/nzbget/scripts/nzbToMedia/autoProcessMedia.cfg
16:03:46|WARNING MAIN: Invalid number of arguments received from client.
16:03:46|INFO    MAIN: Running autoProcessMovie as a manual run...
16:03:46|INFO    MAIN: Calling CouchPotatoServer to post-process: Manual Run
16:03:46|INFO    Loading config from /share/HDA_DATA/Download/nzbget/scripts/nzbToMedia/autoProcessMedia.cfg
16:03:46|WARNING Could not find an imdb id in directory or name
16:03:46|INFO    Postprocessing will continue, but the movie may not be identified correctly by CouchPotato
16:03:46|INFO    Waiting for 0 seconds to allow CPS to process newly extracted files
16:03:46|ERROR   Unable to open URL
Traceback (most recent call last):
  File "/share/HDA_DATA/Download/nzbget/scripts/nzbToMedia/autoProcess/autoProcessMovie.py", line 257, in process
    urlObj = urllib.urlopen(url)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/urllib.py", line 84, in urlopen
    return opener.open(url)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/urllib.py", line 205, in open
    return getattr(self, name)(url)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/urllib.py", line 342, in open_http
    h.endheaders(data)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/httplib.py", line 940, in endheaders
    self._send_output(message_body)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/httplib.py", line 803, in _send_output
    self.send(msg)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/httplib.py", line 755, in send
    self.connect()
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/httplib.py", line 736, in connect
    self.timeout, self.source_address)
  File "/share/HDA_DATA/.qpkg/Python/lib/python2.7/socket.py", line 567, in create_connection
    raise error, msg
IOError: [Errno socket error] [Errno 111] Connection refused
16:03:46|INFO    MAIN: A problem was reported in the autoProcess* script.

Which seems to be fine from my point of view, as the script does load the python modules properly

Therefore, it seems to me that NZBget does load the nzbToSickBeard script with a different python version (I have the strange 2.7.5. installed as well).

Do you have any idea how I can fix this issue? Happy to give a small donation as incentive as NZBGet is still a great tool!

clinton-hall commented 8 years ago

easiest way to be sure is to add

ln -sf /share/HDA_DATA/.qpkg/Python/bin/python2.7 /share/HDA_DATA/.qpkg/Python/bin/python2
export PATH=/share/HDA_DATA/.qpkg/Python/bin:$PATH

into the /etc/init.d/nzbget.sh script just after the other export lines...

spaggi2 commented 8 years ago

Well, applause to you! It works now! Thank you so much. Any way to donate for nzbToMedia?

clinton-hall commented 8 years ago

No problems... Click on my profile and there is a web address shown... That page is just a brief blurb about me, what I do, and why... It also includes PayPal and Bitcoin links...