AttributeError: 'NoneType' object has no attribute 'execute'
ericdorsey opened this issue · 3 comments
ericdorsey commented
Cool idea; wanted to play with this.
OSX 10.9.5
MySQL 5.5.38
Python 2.7.5
Installed http://dev.mysql.com/downloads/connector/python/
Opened new terminal (iTerm2) session
Ran
$ fake2db --rows 200 --db mysql
Got:
Traceback (most recent call last):
File "/usr/local/bin/fake2db", line 8, in <module>
load_entry_point('fake2db==0.1.5', 'console_scripts', 'fake2db')()
File "/Library/Python/2.7/site-packages/fake2db/fake2db.py", line 106, in main
fake_mysql_handler.fake2db_mysql_initiator(host, port, int(args.rows))
File "/Library/Python/2.7/site-packages/fake2db/mysql_handler.py", line 42, in fake2db_mysql_initiator
cursor.execute(tables[key])
AttributeError: 'NoneType' object has no attribute 'execute'
Any thoughts? Thanks!
emirozer commented
Thanks for reporting! I will investigate and provide feedback.
dklesev commented
First error is that there is no password attribute set in mysql_handler.py. So we have a root password defined and it can't connect. Second point is that there are typos after line 87 in mysql_handler.py. And I would add 'IF NOT EXISTS'. And in line 225 is a wrong insert.
fake2db.py
70a71
> parser.add_argument("--passwd", help="OPTIONAL : Pass of root user. ")
104c105
< fake_mysql_handler.fake2db_mysql_initiator(host, port, int(args.rows), str(args.name))
---
> fake_mysql_handler.fake2db_mysql_initiator(str(args.passwd), host, port, int(args.rows), str(args.name))
106c107
< fake_mysql_handler.fake2db_mysql_initiator(host, port, int(args.rows))
---
> fake_mysql_handler.fake2db_mysql_initiator(str(args.passwd), host, port, int(args.rows))
mysql_handler.py
26c26
< def fake2db_mysql_initiator(self, host, port, number_of_rows, name=None):
---
> def fake2db_mysql_initiator(self, passwd, host, port, number_of_rows, name=None):
29a30,31
>
> print "PASS: %s" % passwd
32c34
< cursor, conn = self.database_caller_creator(host, port, name)
---
> cursor, conn = self.database_caller_creator(passwd, host, port, name)
34c36
< cursor, conn = self.database_caller_creator(host, port)
---
> cursor, conn = self.database_caller_creator(passwd, host, port)
57c59
< def database_caller_creator(self, host, port, name=None):
---
> def database_caller_creator(self, passwd, host, port, name=None):
71c73
< conn = mysql.connector.connect(user='root', host=host, port=port)
---
> conn = mysql.connector.connect(user='root', password=passwd , host=host, port=port)
88c90
< "CREATE TABLE `simple_registration` ("
---
> "CREATE TABLE IF NOT EXISTS `simple_registration` ("
96c98
< "CREATE TABLE `simple_registration` ("
---
> "CREATE TABLE IF NOT EXISTS `detailed_registration` ("
108c110
< "CREATE TABLE `user_agent` ("
---
> "CREATE TABLE IF NOT EXISTS `user_agent` ("
117c119
< "CREATE TABLE `user_agent` ("
---
> "CREATE TABLE IF NOT EXISTS `company` ("
128c130
< "CREATE TABLE `simple_registration` ("
---
> "CREATE TABLE IF NOT EXISTS `customer` ("
225c227
< customer_payload = ("INSERT INTO detailed_registration "
---
> customer_payload = ("INSERT INTO customer "
xiaohanyu commented
Seems there's no password for postgres handler?