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

  • Home
  • SEARCH
  • 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 7855321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:20:53+00:00 2026-06-02T20:20:53+00:00

Creating a web-scraper in Python 2.6.4 + Scrapy toolkit. Need to do data analysis,

  • 0

Creating a web-scraper in Python 2.6.4 + Scrapy toolkit. Need to do data analysis, but also my first Python learning project. Having trouble creating the SQL INSERT statement in my pipeline.py. The real query has approximately 30 attributes to insert..

First, is there a better way to write this UPDATE or INSERT algorithm? Open to improvements.

Second, here’s two different syntax variations and the different errors they produce. I’ve tried lots of variations based on examples but can’t find an example using “INSERT SET” breaking across multiple lines. What is the proper syntax?

DB is empty so we’re always branching to ‘INSERT’ block for now.

def _conditional_insert(self, tx, item):
 # create record if doesn't exist.
 tx.execute("SELECT username  FROM profiles_flat WHERE username = %s", (item['username'][0], ))
 result = tx.fetchone()

 if result:
    # do row UPDATE
     tx.execute( \
        """UPDATE profiles_flat SET
        username=`%s`, 
        headline=`%s`,
        age=`%s`
        WHERE username=`%s`""", (  \
        item['username'],
        item['headline'],
        item['age'],)
        item['username'],)
     )         
 else: 
   # do row INSERT
   tx.execute( \
   """INSERT INTO profiles_flat SET
        username=`%s`, 
        headline=`%s`,
        age=`%s` """, ( \
        item['username'],
        item['headline'],
        item['age'], )   # line 222
   )

Error:

[Failure instance: Traceback: <class '_mysql_exceptions.OperationalError'>: (1054, "Unknown column ''missLovely92 '' in 'field list'")
  /usr/lib/python2.6/threading.py:497:__bootstrap
  /usr/lib/python2.6/threading.py:525:__bootstrap_inner
  /usr/lib/python2.6/threading.py:477:run
  --- <exception caught here> ---
  /usr/lib/python2.6/vendor-packages/twisted/python/threadpool.py:210:_worker
  /usr/lib/python2.6/vendor-packages/twisted/python/context.py:59:callWithContext
  /usr/lib/python2.6/vendor-packages/twisted/python/context.py:37:callWithContext
  /usr/lib/python2.6/vendor-packages/twisted/enterprise/adbapi.py:429:_runInteraction
  /export/home/raven/scrapy/project/project/pipelines.py:222:_conditional_insert
  /usr/lib/python2.6/vendor-packages/MySQLdb/cursors.py:166:execute
  /usr/lib/python2.6/vendor-packages/MySQLdb/connections.py:35:defaulterrorhandler
  ]

Alternative Syntax:

  query = """INSERT INTO profiles_flat SET
        username=`%s`, 
        headline=`%s`,
        age=`%s` """ % \
   item['username'], # line 196
   item['headline'],
   item['age']

   tx.execute(query)

Error:

  [Failure instance: Traceback: <type 'exceptions.TypeError'>: not enough arguments for format string
  /usr/lib/python2.6/threading.py:497:__bootstrap
  /usr/lib/python2.6/threading.py:525:__bootstrap_inner
  /usr/lib/python2.6/threading.py:477:run
  --- <exception caught here> ---
  /usr/lib/python2.6/vendor-packages/twisted/python/threadpool.py:210:_worker
  /usr/lib/python2.6/vendor-packages/twisted/python/context.py:59:callWithContext
  /usr/lib/python2.6/vendor-packages/twisted/python/context.py:37:callWithContext
  /usr/lib/python2.6/vendor-packages/twisted/enterprise/adbapi.py:429:_runInteraction
  /export/home/raven/scrapy/project/project/pipelines.py:196:_conditional_insert
  ]    
  • 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-06-02T20:20:54+00:00Added an answer on June 2, 2026 at 8:20 pm

    You shouldn’t surround values with backticks. Backticks are used to quote column names.

    INSERT INTO profiles_flat (username, headline, age)
    VALUES (%s, %s, %s)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been creating a web scraper for an internal application with PHP but
So far I have been creating Web Portal but recently I had a request
I'm creating a web service that often scrapes data from remote web pages. After
I'm creating web pages (html) every day, but I would like the pages to
I'm creating web application for my friend, a tutor school system. Now, I'm having
If I am creating a simple web scraper (from root url, grab all links,
Not having dealt much with creating web-services, either from scratch, or by breaking apart
Strange exception happens when I work in VS 2010. I'm creating web project and
I've begun creating web apps that use localStorage , and since the data stored
When creating web parts for Sharepoint, is it better to create an actual web

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.