views:

19

answers:

1

i follow this article : here to update data to gae localhost server from mysql.

this is my str_loader.py is :

class College(db.Model):
    cid = db.StringProperty(required=True)
    name = db.StringProperty(required=True)

class MySQLLoader(bulkloader.Loader):
    def generate_records(self, filename):
        """Generates records from a MySQL database."""
        conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
        cursor = conn.cursor()
        sql ="select * from haha"
        cursor.execute(sql)
        #alldata = cursor.fetchall()
        return iter(cursor.fetchone, None)

class Mysql_update(bulkloader.Loader):
    def __init__(self):
        MySQLLoader.__init__(self,'College',
                                   [
                                    ('cid', str),
                                    ('name', lambda x: unicode(x, 'utf8')),
                                   ])
                                   ])

loaders = [Mysql_update]

and i use this code to run :

appcfg.py upload_data --application=zjm1126 --config_file=upload/str_loader.py --filename=b.csv --kind=College --url=http://localhost:8100/remote_api

but it show error :

alt text

so i change str_loader.py :

class Mysql_update(bulkloader.Loader):
    def __init__(self):
        MySQLLoader('College',
                                   [
                                    ('cid', str),
                                    ('name', lambda x: unicode(x, 'utf8')),
                                   ])

and it show this error :

alt text

so i want to know : what should i do ,

thanks

updated

it is ok now :

class MySQLLoader(bulkloader.Loader):
    def generate_records(self, filename):
        """Generates records from a MySQL database."""
        conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
        cursor = conn.cursor()
        sql ="select * from haha"
        cursor.execute(sql)
        rs = cursor.fetchall()
        #return iter(cursor.fetchone, None)
        for x in rs:
            yield (x[0].encode('utf8'),x[1].encode('utf8'))
A: 

Your Mysql_update class needs to subclass MySQLLoader, not bulkloader.Loader.

Nick Johnson
thanks very much ..
zjm1126