Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Issue with slash symbol in @route declaration

CigarasCigaras Posts: 113Members ✭✭
edited March 7 in Channel Development

I have an issue with dynamic @route declaration:

@handler('test')
def MainMenu():
    oc = ObjectContainer()
    group = Prefs['group'] # for example aaa/bbb
    oc.add(DirectoryObject(key = Callback(ListItems, group = unicode(group)), title = group))
    return oc

@route('test/listitems/{group}', page = int)
def ListItems(group, page = 1):
    items = Dict[group]
    for item in items:
        ....

I get an error stating that url test/listitems/aaa/bbb is not found, how can I escape it to something like test/listitems/aaa&#47bbb or similar? aaa/bbb value is being red from preferences, provided by user.

If I drop the {group} from @route I see this in log file:

DEBUG (runtime:717) - Handling request GET /video/iptv/listitems?group=aaa%2Fbbb

So Plex is able to change / to %2F in some situations, I want to force Plex to do so in @route, so I could get this:

DEBUG (runtime:717) - Handling request GET /video/iptv/listitems/aaa%2Fbbb

P. S. On one hand omitting the {group} might be a solution, but if group text has unicode symbols the "unicodeness" is lost when passing group as a parameter to a procedure and group is not a part of a @route, but this is a different question.

Best Answer

Answers

  • TwoureTwoure Posts: 621Members ✭✭✭

    Maybe:

    # Encode with Plex's custom base64 Encode/Decode
    group = E(Prefs['group'])
    
    # then when you need it later
    items = Dict[D(group)]
    

    E() and D() are aliases for Encode() and Decode() respectively.

    Info taken from utilkit.py:

    def Encode(s):
        """
            Encodes the given string using the framework's standard encoding (a slight variant on
            Base64 which ensures that the string can be safely used as part of a URL).
        """
        ...
    
    def Decode(self, s):
        """
            Decodes a string previously encoded using the above function.
        """
        ...
    
  • CigarasCigaras Posts: 113Members ✭✭
    edited March 7

    If I drop the {group} from @route I see this in log file:

    DEBUG (runtime:717) - Handling request GET /video/iptv/listitems?group=aaa%2Fbbb
    

    So Plex is able to change / to %2F in some situations, I want to force Plex to do so in @route, so I could get this:

    DEBUG (runtime:717) - Handling request GET /video/iptv/listitems/aaa%2Fbbb
    

    P. S. On one hand omitting the {group} might be a solution, but if group text has unicode symbols the "unicodeness" is lost when passing group as a parameter to a procedure and group is not a part of a @route, but this is a different question.

  • sander1sander1 Channel Developer/Admin Posts: 3,559Members, Plex Pass, Plex Ninja Plex Ninja

    @Cigaras said:
    If I drop the {group} from @route I see this in log file:

    DEBUG (runtime:717) - Handling request GET /video/iptv/listitems?group=aaa%2Fbbb
    

    GET parameters are automatically encoded into a safe string. When you create a route, you have to do that yourself. The solution is mentioned by dane22 above.

Sign In or Register to comment.