_mysql_exceptions.Warning: Incorrect string value: '\xE7\xB9\x81\xE9\xAB\x94...' for column 'html' at row 1
def getSource(theurl, moved = 0):
if moved == 1:
theurl = urllib2.urlopen(theurl).geturl()
urlReq = urllib2.Request(theurl)
urlReq.add_header('User-Agent',random.choice(agents))
urlResponse = urllib2.urlopen(urlReq)
htmlSource = urlResponse.read()
return htmlSource
new_u = Url(source_url = source_url, source_url_short = source_url_short, source_url_hash = source_url_hash, html = htmlSource)
new_u.save()
爲什麼會發生這種情況? 我基本上是下載頁面的URL ...然後使用Django將它保存到數據庫中。INSERT進入MySQL時出現錯誤
它只發生有時....有時它工作正常。
編輯:好像我必須將數據庫設置爲UTF-8?什麼是這樣做的命令?
您在哪裏執行查詢的代碼... – Bobby 2009-11-27 12:25:05
Bobby,查詢是new_u,new_u.save()。這是Django查詢 – TIMEX 2009-11-27 12:25:38
@alex:哦......從來沒有與該系統工作。可能最好的猜測是,你不會逃避html-String,他試圖插入'錯誤'的值。對於PHP的功能稱爲mysql_real_escape_string。 – Bobby 2009-11-27 12:27:46