こんにちは、私は現在pythonで作業しています。クエリを使用してデータベースからデータを選択するファイルがあります。しかし、タイムスタンプでフィルタリングされたデータを選択したいと思います。すべてのデータを選択できます(単純な選択で...テーブルなどから)。しかし、クエリ全体に WHERE クエリを追加すると、プログラムは失敗します。
誰かが私を助けてくれることを願っています。
これまでの私のコードは次のとおりです。
import datetime
import time
import mysql.connector
ts = '2013-10-21 00:00:00'
f = '%Y-%m-%d %H:%M:%S'
now = datetime.datetime.strptime(ts,f)
print (now)
time.strftime('%Y-%m-%d %H:%M:%S')
print (time.strftime)
connection = mysql.connector.connect(user='**', password='**', host='**', database='*dbname*')
cursor = connection.cursor()
str_now = now.date().isoformat()
query = ("SELECT version, protocol, ttl, des_address, des_port, source_address, source_port, timestamp FROM *tablename* **WHERE timestamp = %s", (str_now))**
cursor.execute(query)
for (version, protocol, ttl, des_address, des_port, source_address, source_port, timestamp) in cursor:
print("Version:"+str(version),"Protocol:" + str(protocol),
"TTL:" + str(ttl), "Destination Address:" + str(des_address),
"Destination Port:" + str(des_port), "Source Address:" + str(source_address),
"Source Port:" + str(source_port), "Timestamp:" + str(timestamp))
print (cursor.lastrowid)
このコードを実行すると、「AttributeError: 'tuple' object has no attribute 'encode'」というエラーが表示されます。
Google で検索しても、適切な回答が見つかりません。
敬具