IndexError: tuple index out of range postgresql












1















I have been using the pgcrypto extension module's digest function to encode several values. I recently discovered that some of the URL values that I'm trying to encode contain '%,' which throw an




IndexError: tuple index out of range.




I have spent hours today trying to fix this issue, but so far I have not corrected this error in my code. How do I encode a URL that contains special characters?



This works in pgAdmin4, but not in my python script:



encode(digest('domainname.com/pub-cgi/retrieve.pl?doc=file%2F1999&zone_19=300%2A%20','sha256')


How do I encode a URL that contains special characters?










share|improve this question




















  • 1





    Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

    – DBrowne
    Nov 21 '18 at 1:12











  • That extra closing quote was added by mistake when I sanitized the snippet for posting.

    – Life is complex
    Nov 21 '18 at 1:18











  • The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

    – Life is complex
    Nov 21 '18 at 1:24
















1















I have been using the pgcrypto extension module's digest function to encode several values. I recently discovered that some of the URL values that I'm trying to encode contain '%,' which throw an




IndexError: tuple index out of range.




I have spent hours today trying to fix this issue, but so far I have not corrected this error in my code. How do I encode a URL that contains special characters?



This works in pgAdmin4, but not in my python script:



encode(digest('domainname.com/pub-cgi/retrieve.pl?doc=file%2F1999&zone_19=300%2A%20','sha256')


How do I encode a URL that contains special characters?










share|improve this question




















  • 1





    Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

    – DBrowne
    Nov 21 '18 at 1:12











  • That extra closing quote was added by mistake when I sanitized the snippet for posting.

    – Life is complex
    Nov 21 '18 at 1:18











  • The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

    – Life is complex
    Nov 21 '18 at 1:24














1












1








1


0






I have been using the pgcrypto extension module's digest function to encode several values. I recently discovered that some of the URL values that I'm trying to encode contain '%,' which throw an




IndexError: tuple index out of range.




I have spent hours today trying to fix this issue, but so far I have not corrected this error in my code. How do I encode a URL that contains special characters?



This works in pgAdmin4, but not in my python script:



encode(digest('domainname.com/pub-cgi/retrieve.pl?doc=file%2F1999&zone_19=300%2A%20','sha256')


How do I encode a URL that contains special characters?










share|improve this question
















I have been using the pgcrypto extension module's digest function to encode several values. I recently discovered that some of the URL values that I'm trying to encode contain '%,' which throw an




IndexError: tuple index out of range.




I have spent hours today trying to fix this issue, but so far I have not corrected this error in my code. How do I encode a URL that contains special characters?



This works in pgAdmin4, but not in my python script:



encode(digest('domainname.com/pub-cgi/retrieve.pl?doc=file%2F1999&zone_19=300%2A%20','sha256')


How do I encode a URL that contains special characters?







python python-3.x postgresql pgcrypto






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 1:14







Life is complex

















asked Nov 21 '18 at 0:42









Life is complexLife is complex

452314




452314








  • 1





    Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

    – DBrowne
    Nov 21 '18 at 1:12











  • That extra closing quote was added by mistake when I sanitized the snippet for posting.

    – Life is complex
    Nov 21 '18 at 1:18











  • The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

    – Life is complex
    Nov 21 '18 at 1:24














  • 1





    Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

    – DBrowne
    Nov 21 '18 at 1:12











  • That extra closing quote was added by mistake when I sanitized the snippet for posting.

    – Life is complex
    Nov 21 '18 at 1:18











  • The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

    – Life is complex
    Nov 21 '18 at 1:24








1




1





Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

– DBrowne
Nov 21 '18 at 1:12





Please post your code exactly how it is in your program. The snippet you have provided contains a syntax error (extra closing quote) and won't run. You will also get better answers if you post a complete traceback.

– DBrowne
Nov 21 '18 at 1:12













That extra closing quote was added by mistake when I sanitized the snippet for posting.

– Life is complex
Nov 21 '18 at 1:18





That extra closing quote was added by mistake when I sanitized the snippet for posting.

– Life is complex
Nov 21 '18 at 1:18













The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

– Life is complex
Nov 21 '18 at 1:24





The only URLs that throw this error contain a %. If I remove this encoding piece from my code everything loads correctly including the other elements, which I encoded.

– Life is complex
Nov 21 '18 at 1:24












1 Answer
1






active

oldest

votes


















0














After doing some more research on Stack Overflow, I found a solution that was posted years ago.



Decode escaped characters in URL



This is the code that I used to solve my encoding problem:



# This section of code reformats a href with URL encoding
def unquote(url):
return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)

# URL with encoding - https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf

print (unquote('https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf'))

# Output - https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf


Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.



encode(digest('https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf','sha256')


SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403733%2findexerror-tuple-index-out-of-range-postgresql%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After doing some more research on Stack Overflow, I found a solution that was posted years ago.



    Decode escaped characters in URL



    This is the code that I used to solve my encoding problem:



    # This section of code reformats a href with URL encoding
    def unquote(url):
    return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)

    # URL with encoding - https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf

    print (unquote('https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf'))

    # Output - https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf


    Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.



    encode(digest('https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf','sha256')


    SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.






    share|improve this answer




























      0














      After doing some more research on Stack Overflow, I found a solution that was posted years ago.



      Decode escaped characters in URL



      This is the code that I used to solve my encoding problem:



      # This section of code reformats a href with URL encoding
      def unquote(url):
      return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)

      # URL with encoding - https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf

      print (unquote('https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf'))

      # Output - https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf


      Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.



      encode(digest('https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf','sha256')


      SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.






      share|improve this answer


























        0












        0








        0







        After doing some more research on Stack Overflow, I found a solution that was posted years ago.



        Decode escaped characters in URL



        This is the code that I used to solve my encoding problem:



        # This section of code reformats a href with URL encoding
        def unquote(url):
        return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)

        # URL with encoding - https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf

        print (unquote('https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf'))

        # Output - https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf


        Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.



        encode(digest('https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf','sha256')


        SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.






        share|improve this answer













        After doing some more research on Stack Overflow, I found a solution that was posted years ago.



        Decode escaped characters in URL



        This is the code that I used to solve my encoding problem:



        # This section of code reformats a href with URL encoding
        def unquote(url):
        return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)

        # URL with encoding - https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf

        print (unquote('https://www.somedomainname.com/pubs/retrieve.pl?doc=some%2Ddocument%2Dname.pdf'))

        # Output - https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf


        Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.



        encode(digest('https://www.somedomainname.com/pubs/retrieve.pl?doc=some-document-name.pdf','sha256')


        SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 13:32









        Life is complexLife is complex

        452314




        452314
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403733%2findexerror-tuple-index-out-of-range-postgresql%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to send String Array data to Server using php in android

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Is anime1.com a legal site for watching anime?