0

Hello I new in the sqlite world and here is my problem. Trying to fix a twitter bot an error occured. Here is the code to modify and the error. Tell me if you need the entire code or other informations

def CreateTables(user):
   connexion = sqlite3.connect('data.db')
   c = connexion.cursor()
   c.execute('''CREATE TABLE IF NOT EXISTS {tab}
   (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, compte text, date DATE);'''.format(tab=user.screen_name))
   c.close()
   connexion.commit()
Traceback (most recent call last):
  File "C:\Users\User\Documents\Terminale\Python\Twitter bot\BotTwitter-master\main.py", line 53, in <module>
    GestionFollow.CreateTables(user)
  File "C:\Users\User\Documents\Terminale\Python\Twitter bot\BotTwitter-master\GestionFollow.py", line 12, in CreateTables
    (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, compte text, date DATE);'''.format(tab=user.screen_name))
sqlite3.OperationalError: unrecognized token: "361Yra"

Hugo361
  • 1
  • 1

1 Answers1

0

You are trying to create a table with a name that starts with a digit: 361Yra and this is not allowed.
What you can do is enclose the name in square brackets: [361Yra]
Although I'm not an expert in Python, use something like this:

.format(tab="[" + user.screen_name + "]")
forpas
  • 160,666
  • 10
  • 38
  • 76