Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:07:38+00:00 2026-05-30T17:07:38+00:00

Possible Duplicate: tweepy stream to sqlite database – invalid synatx I’m getting a syntax

  • 0

Possible Duplicate:
tweepy stream to sqlite database – invalid synatx

I’m getting a syntax error in my code and I can’t figure out what’s causing it. This is the error the console is returning and nothing is being inputed to the sqlite file.

Filtering the public timeline for "@lunchboxhq"
RT @LunchboxHQ: @lunchboxhq test1   LunchboxHQ  2012-02-27 17:26:14 Echofon
Encountered Exception: near "?": syntax error
@LunchboxHQ test 1  LunchboxHQ  2012-02-27 17:26:36 Echofon
Encountered Exception: near "?": syntax error
@LunchboxHQ test 2  LunchboxHQ  2012-02-27 17:26:51 Echofon
Encountered Exception: near "?": syntax error

my sqlite file only has:

... tableTWEETSTWEETSCREATE TABLE TWEETS(txt text, author text, created int, source text)

Can you guys help me figure out what I’m doing wrong? Thanks. The code is below.

import sys
import tweepy
import webbrowser
import sqlite3 as lite

# Query terms

Q = sys.argv[1:]

sqlite3file='/var/www/twitter.lbox.com/html/stream5_log.sqlite'

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

con = lite.connect(sqlite3file)
cur = con.cursor()
cur.execute("CREATE TABLE TWEETS(txt text, author text, created int, source text)")

class CustomStreamListener(tweepy.StreamListener):

    def on_status(self, status):

        try:
            print "%s\t%s\t%s\t%s" % (status.text, 
                                      status.author.screen_name, 
                                      status.created_at, 
                                      status.source,)

            cur.executemany("INSERT INTO TWEETS(?, ?, ?, ?)", (status.text, 
                                                            status.author.screen_name, 
                                                            status.created_at, 
                                                            status.source))

        except Exception, e:
            print >> sys.stderr, 'Encountered Exception:', e
            pass

    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream

streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)

print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' '.join(sys.argv[1:]),)

streaming_api.filter(follow=None, track=Q)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:07:39+00:00Added an answer on May 30, 2026 at 5:07 pm

    On the executemany you have three “?”-marks but 4 parameters. It is probably missing an additional questionmark. Also you should probably just use execute instead of executemany since you only do one insert. Like this:

    cur.execute("INSERT INTO TWEETS(?, ?, ?, ?)", (status.text, 
                                                   status.author.screen_name, 
                                                   status.created_at, 
                                                   status.source))
    

    Also the correct SQL according to this would be:

    INSERT INTO TWEETS VALUES(?, ?, ?, ?)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: How can I increment a date by one day in Java? I
Possible Duplicate: How can I properly handle 404 in ASP.NET MVC? I've made the
Possible Duplicate: How to: URL re-writing in PHP? How can a website use an
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.