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

Can't make it work on PMS Windows (500 for all plugin frontend content) #189

Closed
byg0n3 opened this issue Jul 14, 2016 · 29 comments
Closed
Assignees
Milestone

Comments

@byg0n3
Copy link

byg0n3 commented Jul 14, 2016

Was running PMS for like 5 month or so. Few days ago tried to install web tools for the first time and faced with this problem. Firstly, I thought that it can be related to my PMS, due to my own channel scripting, so I decided to remove it and make a fresh installation. Unfortunately, it didn't help.
Also, everything working fine on my virtualbox with Linux Mint on the board.
Any ideas or suggestions?
3dvi4fm 1
hekcupx 1
system_and_webtools_logs.zip

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Seems like a unicode problem, and maybe due to the path:

C:\Users\dein0s

What codepage/language are you running, and what's the correct path in above?

/T

@ukdtom ukdtom self-assigned this Jul 14, 2016
@ukdtom ukdtom added the bug label Jul 14, 2016
@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

System-wide language is Russian (cp1251).
Direct path looks like this:
c:\Users\dein0s\AppData\Local\Plex Media Server\Plug-ins\WebTools.bundle\

Never had any problems with this username. Latin chars, number, no spaces. What can go wrong?

Also, looks like backend working as intended. I can send POST on login with no problems.
yzgaavb 1

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

After been authenticated towards the backend, try and issue a get like:

http://127.0.0.1:33400/webtools2?module=wt&function=getCSS

Does that return an array with css files?
Like:
[ "trumpy81-Aussie.css", "trumpy81-ItsPink.css", "trumpy81-Plex.css", "trumpy81-Teal.css", "trumpy81-ItsRed.css", "trumpy81-ItsBlue.css", "trumpy81-ItsGreen.css", "trumpy81-theme1.css" ]

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Yep.
wfkid2r 1

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Hmmm......
https://bugs.python.org/issue9291

So need some time to dig into this, and not sure it's something I can fix, since python comes with PMS :-(

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

And the problem, FUI according to your log:

2016-07-14 11:38:06,973 (25a8) : CRITICAL (core:574) - Exception (most recent call last): File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-a17e99e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\runtime.py", line 843, in handle_request result = f(**d) File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-a17e99e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\handlers\resources.py", line 83, in resource return Framework.objects.DataObject(self._core, resource, Framework.utils.guess_mime_type(resource_name)) File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-a17e99e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\utils.py", line 40, in guess_mime_type mtype = mimetypes.guess_type(filename)[0] File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\mimetypes.py", line 294, in guess_type init() File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\mimetypes.py", line 355, in init db.read_windows_registry() File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\mimetypes.py", line 259, in read_windows_registry for ctype in enum_types(mimedb): File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\mimetypes.py", line 249, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'utf8' codec can't decode byte 0xe0 in position 0: invalid continuation byte

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

As far as I remember (investigated it also some time ago), this was only affecting images from ./Contents/Resources/
In a result - custom icons are not displayed for channels, but that's all. Everything else works without problems.

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Since I haven't got a russian windows, I need you to work with me here ;-)

Make a backup of the file named __init__.py located in the WT Install dir/Contents/Code, and then replace it with the attached one.
Restart PMS, and after WT is up running again, I need the WT logs once more.
Also please tell me if attached makes a difference at all?

init.py.zip

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Was thinking about some monkeypatching of included mimetypes.py, but it seems that your code do the right magic :)
sys.setdefaultencoding("cp1251")
Everything works now.

2016-07-14 14:29:00,773 (12f8) : DEBUG (logkit:13) - ******* Started WebTools V2.2 on Windows *********** 2016-07-14 14:29:00,773 (12f8) : DEBUG (logkit:13) - Testing encoding: utf-8 2016-07-14 14:29:00,773 (12f8) : DEBUG (logkit:13) - Default set to cp1251

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Logs please, since I need to make it work only on Windows, and need something to detect, instead of just forcing it to russian, since that will break it for everybody else not running russian ;-)

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Yeah, sure! Almost forgot about them on that happy train.

And now it even loads images from
./Contents/Resources/

Seems like plex devs need to update python they provide.
wt_logs.zip

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Darn, it still reports utf-8 :-(

Hang in there please, while I cook up a new version of the file

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Btw, you can just provide me the code instead of new files if this suits you.

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

It does ;-)

Replace the start function with below, and then report back please:

`def Start():
global SECRETKEY
global VERSION
global DEBUGMODE
# Switch to debug mode if needed
debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
DEBUGMODE = os.path.isfile(debugFile)
if DEBUGMODE:
VERSION = VERSION + ' ****** WARNING Debug mode on *_'
print("***** Started %s on %s *********" %(NAME + ' V' + VERSION, Platform.OS))
Log.Debug("_
* Started %s on %s ***********" %(NAME + ' V' + VERSION, Platform.OS))

Log.Debug("Testing encoding: " + sys.getdefaultencoding())



HTTP.CacheTime = 0
try:
    DirectoryObject.thumb = R(ICON)
except UnicodeEncodeError:
    sys.setdefaultencoding("cp1251")
    Log.Debug("Default set to cp1251")
    DirectoryObject.thumb = R(ICON)
    pass

ObjectContainer.title1 = NAME + ' V' + VERSION 
Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
ObjectContainer.view_group = 'List'
makeSettings()

# Get the secret key used to access the PMS framework ********** FUTURE USE ***************
SECRETKEY = genSecretKeyAsStr()
startWeb(SECRETKEY, VERSION, DEBUGMODE)`

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Scratch above.....Github is formating it badly :-(

Use below instead

init.py.zip

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Already testing.
And you should use triple ` at the start and end of your code block, then it keeps everything inside formatted without any exceptions.
Like this:

def Start():
    global SECRETKEY
    global VERSION
    global DEBUGMODE
    # Switch to debug mode if needed
    debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
    DEBUGMODE = os.path.isfile(debugFile)
    if DEBUGMODE:
    VERSION = VERSION + ' ****** WARNING Debug mode on ******'
    print("***** Started %s on %s *******" %(NAME + ' V' + VERSION, Platform.OS))
    Log.Debug("**** Started %s on %s ***********" %(NAME + ' V' + VERSION, Platform.OS))
    Log.Debug("Testing encoding: " + sys.getdefaultencoding())
    HTTP.CacheTime = 0
    try:
        DirectoryObject.thumb = R(ICON)
    except UnicodeEncodeError:
        sys.setdefaultencoding("cp1251")
        Log.Debug("Default set to cp1251")
        DirectoryObject.thumb = R(ICON)
        pass

    ObjectContainer.title1 = NAME + ' V' + VERSION
    Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
    ObjectContainer.view_group = 'List'
    makeSettings()

    # Get the secret key used to access the PMS framework ********** FUTURE USE ***************
    SECRETKEY = genSecretKeyAsStr()
    startWeb(SECRETKEY, VERSION, DEBUGMODE)

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Nice, and thanks for the hint.
Now a tripping foot here while I await the results ;-)

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Ain't worked.
Guess your code should catch
UnicodeDecodeError
and not
UnicodeEncodeError.

Retesting now.

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Ahhh....Nice catch ;-)

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Still doesn't work with any of variants.

wt_logs_encode_and_decode_catch_logs.zip

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Looks like setting path to icon object doesn't act like a call, so it can't reach except block.

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Please try this:

Add an import statement @ the top like:
import locale

Then try this:

    Log.Debug("Testing encoding: " + sys.getdefaultencoding())
    Log.Debug("Testing locale: " + locale.getpreferredencoding())

And tell me what the log says

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

2016-07-14 15:20:54,661 (6c0) :  DEBUG (logkit:13) - Testing encoding: utf-8
2016-07-14 15:20:54,661 (6c0) :  DEBUG (logkit:13) - Testing locale: cp1251

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Ahhhh.......Standby

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

def Start():
    global SECRETKEY
    global VERSION
    global DEBUGMODE
    # Switch to debug mode if needed
    debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
    DEBUGMODE = os.path.isfile(debugFile)
    if DEBUGMODE:
        VERSION = VERSION + ' ****** WARNING Debug mode on *********'
        print("********  Started %s on %s  **********" %(NAME  + ' V' + VERSION, Platform.OS))
    Log.Debug("*******  Started %s on %s  ***********" %(NAME + ' V' + VERSION, Platform.OS))
    if (Platform.OS == 'Windows' and locale.getpreferredencoding() == 'cp1251'):
        sys.setdefaultencoding("cp1251")
        Log.Debug("Default set to cp1251")
    HTTP.CacheTime = 0
    DirectoryObject.thumb = R(ICON)
    ObjectContainer.title1 = NAME + ' V' + VERSION 
    Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
    ObjectContainer.view_group = 'List'
    makeSettings()

    # Get the secret key used to access the PMS framework ********** FUTURE USE ***************
    SECRETKEY = genSecretKeyAsStr()
    startWeb(SECRETKEY, VERSION, DEBUGMODE)

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Looks good, everything working.

@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Thanks for working with me on this.
I pinged Plex and asked for an update of the bundled Python, but not getting my hopes up too high here, so regardless, I'll make sure the next version of WebTools has the workaround from above ;-)

@byg0n3
Copy link
Author

byg0n3 commented Jul 14, 2016

Thank you too for such collaboration :)
Now will do some fixes for my own channels regarding to this issue.

Also hope that plex devs will update python in their distribution. And maybe will finally provide fully updated documentation for their framework and api :D

@ukdtom ukdtom added this to the V2.3 milestone Jul 14, 2016
ukdtom added a commit that referenced this issue Jul 14, 2016
@ukdtom
Copy link
Owner

ukdtom commented Jul 14, 2016

Fixed with 5df58bf

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

No branches or pull requests

2 participants