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?
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:
Now that I have this URL reformatted, I can use the pgcrypto extension module's digest function to encode with a SHA-256 hash.
SPECIAL NOTE: I remove the href protocol from the URLs prior to hashing them, because it prevents duplicates, which is a concern of mine.