“'utf-8' codec can't decode byte” when querying string in MySQL

拈花ヽ惹草 提交于 2019-12-08 11:35:21

问题


I'm quering to see if a particular URL exists in my table:

query = 'SELECT EXISTS(SELECT * FROM table WHERE LINK = %s)'
c.execute(query, [link])
result = c.fetchall()[0][0]

If I set link equal to "https://www.reuters.com/article/us-mideast-iran-tanker/iran-threatens-british-shipping-in-retaliation-for-tanker-seizure-idUSKCN1U00S5", it works fine. But when I specifically try:

query = 'SELECT EXISTS(SELECT * FROM table WHERE LINK = %s)'
c.execute(query, ["
https://www.reuters.com/article/brief-katanga-mining-receives-confirmati/brief-katanga-mining-receives-confirmation-from-kamoto-copper-co-that-armed-forces-of-drc-are-in-area-around-operations-of-kcc-idUSFWN24502R"])

I get:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1: invalid start byte

This happened for another long URL. But the column type is mediumtext, and it's the same type I'm using for much longer strings.

来源:https://stackoverflow.com/questions/56911675/utf-8-codec-cant-decode-byte-when-querying-string-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!