ConfigParser and Scrapy: NoSectionError
Question: I have a issue with my Scrapy crawler when I launch it.

I used ConfigParser in order to have a small config.ini to set my table name
which i create each time i launch the crawler to scrap. That a basic way to
scrap but i'm still noob with scrapy and python

I get the folowings errors:

    
    
    File "c:\python27\lib\ConfigParser.py", line 279, in options
        raise NoSectionError(section)
    ConfigParser.NoSectionError: No section: 'SectionOne'
    2016-02-04 15:10:57 [twisted] CRITICAL:
    

Here is my config.py:

    
    
    import ConfigParser 
    import os
    
    Config = ConfigParser.ConfigParser()
    Config.read(os.getcwd() + '/config.ini')
    
    def ConfigSectionMap(section):
        dict1 = {}
        options = Config.options(section)
        for option in options:
            try:
               dict1[option] = Config.get(section, option)
               if dict1[option] == -1:
                   DebugPrint("skip: %s" % option)
            except:
                print("exception on %s!" % option)
                dict1[option] = None
        return dict1
    

Here is my config.ini

    
    
    [SectionOne]
    nom_table: Seche_cheveux
    

Here is my pipeline.py:

    
    
    import sqlite3
    from datetime import date, datetime
    import os
    from config import *
    
    TableName = ConfigSectionMap("SectionOne")['nom_table']
    print TableName
    
    
    class  sqlite3Pipeline(object):
    
        def __init__(self):
            #initialisation de la base et connexion
            try:
                #self.setupDBCon()
                self.con = sqlite3.connect(os.getcwd() + '/db.sqlite')
                self.cur = self.con.cursor()
                self.table_name = TableName
                self.createTables()
            except sqlite3.Error as e:
                raise e
    
    
        def createTables(self):
            self.createMgTable()
    
        def closeDB(self):
            self.con.close()
    
        def __del__(self):
            self.closeDB()
    
        def createMgTable(self, table_name):
            self.cur.execute("CREATE TABLE IF NOT EXISTS" + table_name + "(\
            nom TEXT UNIQUE, \
            url TEXT UNIQUE, \
            prix TEXT, \
            stock TEXT, \
            revendeur TEXT, \
            livraison TEXT, \
            img TEXT UNIQUE, \
            detail TEXT UNIQUE, \
            bullet TEXT UNIQUE, \
            created_at DATE \
            )")
    
        def process_item(self, item, spider):
            self.storeInDb(item)
            return item
    
        def storeInDb(self,item):
           etc....
           etc...
    

Please can you tell me how i can handle configparser with scrapy crawler ? and
if possible tell me what i'm doing wrong

For info when i start each file seperatly ,all print function i included works
welll.


Answer: `ConfigParser.read()` tends to fail silently when the config file is not
found. There's probably a change in the current working directory
(`os.getcwd()`) that prevents it from finding `config.ini`.

If your `config.ini` file is next to your `config.py`, you can use this
instead:

    
    
    Config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
    

