Inserting url encoded in postgreSQL adds extra '%' symbols
DLAcoding opened this issue · 1 comments
DLAcoding commented
I have noticed that when I try to insert in postgresql urls which contains '%C3' is inserted as '%%C3': For example:
https://www.amazon.es/Desesperaci%C3%B3n-BEST-SELLER-Stephen-King/dp/8497595890
is inserted as https://www.amazon.es/Desesperaci%%C3%%B3n-BEST-SELLER-Stephen-King/dp/8497595890
If the same statement is executed in sqlite3 DB there is no added '%' symbol, so the problem is when I use it in postgreSQL.
Code with CS50:
url = 'https://www.amazon.es/Desesperaci%C3%B3n-BEST-SELLER-Stephen-King/dp/8497595890'
db = cs50.SQL("postgresql://myDDBB")
db.execute("INSERT INTO urls (url, url2) VALUES (?,?)",url,'cs50')
Now if I execute it using psycopg2
package, the url is inserted with no added '%' symbol (works ok as with a sqlite3 DB).
engine = psycopg2.connect("postgres://myDDBB")
cur = engine.cursor()
cur.execute("INSERT INTO urls (url, url2) VALUES (%s,%s)", (url,"pysco2"))
engine.commit()
Am I missing something?
UPDATE
Also tried with sqlalchemy
without any issues:
from sqlalchemy import create_engine
db = create_engine("postgresql://myDDBB")
db.execute("INSERT INTO urls (url, url2) VALUES (%s,%s)",url,'sqalchemy')