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 8583911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:38:51+00:00 2026-06-11T21:38:51+00:00

I am trying to use reflect feature of sqlalchemy but running into issues. This

  • 0

I am trying to use reflect feature of sqlalchemy but running into issues.

This is the mysql table i am trying to reflect.

| Country | CREATE TABLE `Country` (
  `Code` varchar(8) NOT NULL,
  `Country` varchar(64) NOT NULL,
  `IsValid` varchar(1) DEFAULT 'Y',
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

Reflecting code(sch.py).

from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy
import eng

#Base = sqlalchemy.ext.declarative.declarative_base()
Base = declarative_base()

country = Table('Country',eng.Meta,autoload=True)
class Country(Base):    
    __tablename__ = country
    __mapper_args = {
        'primary_key' : [country.c.Code]
    }

eng.py

import sqlalchemy
import sqlalchemy.orm

eng = sqlalchemy.create_engine('mysql://user:pass@host/db',echo=True)

Meta = sqlalchemy.MetaData()
Meta.bind = eng

sesDec = sqlalchemy.orm.sessionmaker(bind=eng)

When i import sch i get error.

import sqlalchemy
from sch import Country
import eng

ses = eng.sesDec()

res = ses.query(Country.Code.label('Code'),Country.Country.label('Country'))

for rec in res.filter(Country.IsValid == 'Y').filter(Country.Code.like('A%')).order_by(Country.Code).all():
    print rec

Error(bottom of stack-trace)

  File "/pythonlib/lib64/python2.4/site-packages/sqlalchemy/sql/expression.py", line 4198, in description
    return self.name.encode('ascii', 'backslashreplace')
AttributeError: 'Table' object has no attribute 'encode
  • 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-11T21:38:52+00:00Added an answer on June 11, 2026 at 9:38 pm
    class Country(Base):    
        __tablename__ = country
    

    Did you mean __table__ = country?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code: I'm trying to remove the categoryPath node but keep its
I am trying to use matplotlib to create a graph to reflect real time
I'm trying to use the following to create a Spinner . But I get
I'm trying to use Java annotations, but can't seem to get my code to
I am need paint my image. I'm trying use JQuery in here this link:
i am trying to use aop pointcut stuff for transaction but gettig error i
I am trying to create a form in Access based on a table and
I'm trying to use scala.reflect to get the class attributes and to write them
I am trying to use the ImageLoader class from libs-for-android (http://code.google.com/p/libs-for-android/), and am getting
I'm trying to reflect over some class properties and set them programmatically, but it

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.