Note that there are some explanatory texts on larger screens.

plurals
  1. POScrapy: MySQL Pipeline -- Unexpected Errors Encountered
    primarykey
    data
    text
    <p>I'm getting a number of errors, depending upon what is being inserted/updated.</p> <p>Here is the code for processing the item:</p> <pre><code> def process_item(self, item, spider): try: if 'producer' in item: self.cursor.execute("""INSERT INTO Producers (title, producer) VALUES (%s, %s)""", (item['title'], item['producer'])) elif 'actor' in item: self.cursor.execute("""INSERT INTO Actors (title, actor) VALUES (%s, %s)""", (item['title'], item['actor'])) elif 'director' in item: self.cursor.execute("""INSERT INTO Directors (title, director) VALUES (%s, %s)""", (item['title'], item['director'])) else: self.cursor.execute("""UPDATE example_movie SET distributor=%S, rating=%s, genre=%s, budget=%s WHERE title=%s""", (item['distributor'], item['rating'], item['genre'], item['budget'], item['title'])) self.conn.commit() except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) return item </code></pre> <p>Here is an example of the <code>items</code> returned from the scraper:</p> <pre><code> [{'budget': [u'N/A'], 'distributor': [u'Lorimar'], 'genre': [u'Action'], 'rating': [u'R'],'title': [u'Action Jackson']}, {'actor': u'Craig T. Nelson', 'title': [u'Action Jackson']}, {'actor': u'Sharon Stone', 'title': [u'Action Jackson']}, {'actor': u'Carl Weathers', 'title': [u'Action Jackson']}, {'producer': u'Joel Silver', 'title': [u'Action Jackson']}, {'director': u'Craig R. Baxley', 'title': [u'Action Jackson']}] </code></pre> <p>Here are the errors returned:</p> <pre><code> 2013-08-25 23:04:57-0500 [ActorSpider] ERROR: Error processing {'budget': [u'N/A'], 'distributor': [u'Lorimar'], 'genre': [u'Action'], 'rating': [u'R'], 'title': [u'Action Jackson']} Traceback (most recent call last): File "/Library/Python/2.7/site-packages/scrapy/middleware.py", line 62, in _process_chain return process_chain(self.methods[methodname], obj, *args) File "/Library/Python/2.7/site-packages/scrapy/utils/defer.py", line 65, in process_chain d.callback(input) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/defer.py", line 361, in callback self._startRunCallbacks(result) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/defer.py", line 455, in _startRunCallbacks self._runCallbacks() --- &lt;exception caught here&gt; --- File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/defer.py", line 542, in _runCallbacks current.result = callback(current.result, *args, **kw) File "/Users/fortylashes/Documents/Management_Work/BoxOfficeMojo/BoxOfficeMojo/pipelines.py", line 53, in process_item self.cursor.execute("""UPDATE example_movie SET distributor=%S, rating=%s, genre=%s, budget=%s WHERE title=%s""", (item['distributor'], item['rating'], item['genre'], item['budget'], item['title'])) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQLdb/cursors.py", line 159, in execute query = query % db.literal(args) exceptions.ValueError: unsupported format character 'S' (0x53) at index 38 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 'Craig T. Nelson')' at line 1 2013-08-25 23:04:57-0500 [ActorSpider] DEBUG: Scraped from &lt;200 http://www.boxofficemojo.com/movies/?id=actionjackson.htm&gt; {'actor': u'Craig T. Nelson', 'title': [u'Action Jackson']} Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 'Sharon Stone')' at line 1 2013-08-25 23:04:57-0500 [ActorSpider] DEBUG: Scraped from &lt;200 http://www.boxofficemojo.com/movies/?id=actionjackson.htm&gt; {'actor': u'Sharon Stone', 'title': [u'Action Jackson']} Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 'Carl Weathers')' at line 1 2013-08-25 23:04:57-0500 [ActorSpider] DEBUG: Scraped from &lt;200 http://www.boxofficemojo.com/movies/?id=actionjackson.htm&gt; {'actor': u'Carl Weathers', 'title': [u'Action Jackson']} Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 'Joel Silver')' at line 1 2013-08-25 23:04:57-0500 [ActorSpider] DEBUG: Scraped from &lt;200 http://www.boxofficemojo.com/movies/?id=actionjackson.htm&gt; {'producer': u'Joel Silver', 'title': [u'Action Jackson']} Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 'Craig R. Baxley')' at line 1 2013-08-25 23:04:57-0500 [ActorSpider] DEBUG: Scraped from &lt;200 http://www.boxofficemojo.com/movies/?id=actionjackson.htm&gt; {'director': u'Craig R. Baxley', 'title': [u'Action Jackson']} </code></pre> <p>Apparently there are a lot issues. Thank you for reading! Any and all suggestions or ideas are greatly appreciated!</p> <p>::::UPDATE/MORE INFO::::</p> <p>There appear to be three movies, of the test set of 52 total, which are being inserted into the the <code>Actors</code>, <code>Producers</code> and <code>Directors</code> tables. <strong>Note</strong>: The <code>UPDATE</code> statement isn't working at all.</p> <p>These movies are: <code>Abraham Lincoln: Vampire Hunter</code>, <code>Ace Ventura: Pet Detective</code> and <code>Ace Ventura: When Nature Calls</code></p> <p>Interestingly, these are all of the movies that have <code>:</code> in the <code>title</code>- I'm not sure what this means, but if anyone has an idea please share it!</p> <p>:::::INSERT SOLVED:::::</p> <p>Turns out the problem was caused by the <code>scraper</code> putting individual items in a list. So <code>{'actor': [u'this one guy']</code> as opposed top <code>{'actor': u'this one guy'}</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload