Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access database from within a method
    primarykey
    data
    text
    <p>I keep receiving the error, "<strong>TypeError: 'Shard' object is unsubscriptable</strong>."</p> <pre><code>#Establish an on-demand connection to the central database def connectCentral(): engine = engine_from_config(config, 'sqlalchemy.central.') central.engine = engine central.Session.configure(bind=engine) #Establish an on-demand connection to a shard that contains #data for the supplied id def connectShard(id): #If no connection has been made to the central database #make one to determine the shard info if central.engine == None: print 'Connecting to central database' connectCentral() shard_info = central.Session.query(Shard).filter_by(id=id).first() #If no shard exists for the given id, return false if shard_info == None: return 'None' shard.engine = shard_info['sqlite'] shard.Session.configure(bind=shard.engine) c_shard = sa.Table("Shard", central.metadata, sa.Column("id", sa.types.Integer, primary_key=True), sa.Column("ip",sa.types.String(100), nullable=False), sa.Column("username",sa.types.String(100), nullable=False), sa.Column("password",sa.types.String(100), nullable=False), sa.Column("port",sa.types.String(100), nullable=False), sa.Column("active",sa.types.String(100), nullable=False), sa.Column("sqlite",sa.types.String(100), nullable=True) ) </code></pre> <p>The error output is:</p> <pre><code>connectShard(232) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/project/project/model/__init__.py", line 39, in connectShard shard.Session.configure(bind=shard.engine) TypeError: 'Shard' object is unsubscriptable </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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