执行$ python main.py可以收集到数据,但报错

来源:4-21 探测资产信息获取执行演示

十万伏特_皮卡丘

2018-03-01

ssh login and exec command:%s {'info': ('192.168.1.15', 22, 'root', '123456'), 'status': 'success', 'cat /etc/issue': 'Ubuntu 16.04.1 LTS \\n \\l\n\n', 'dmidecode -s system-serial-number': 'VMware-56 4d 63 19 a6 21 0f e3-f4 55 ab 46 9d d5 bc 14\n', 'hostname': 'ubuntu\n', "cat /sys/class/net/[^vtlsb]*/address||esxcfg-vmknic -l|awk '{print $8}'|grep ':'": '00:0c:29:d5:bc:14\n', 'cat /etc/redhat-release': '', 'dmidecode -s system-manufacturer': 'VMware, Inc.\n', 'dmidecode -s system-product-name': 'VMware Virtual Platform\n'}

Password Login ... {'192.168.1.15': ('22', '123456', 'root', 'Ubuntu 16.04', 'ubuntu\n', '000c29d5bc14_', 'VMware-564d6319a6210fe3-f455ab469dd5bc14\n', 'VMware, Inc.VMware Virtual Platform')} {}

Key Login ... {} {}

(535, 'Error: authentication failed')

Traceback (most recent call last):

  File "main.py", line 202, in <module>

    main()

  File "main.py", line 127, in main

    key_ip_dic = ft.run()

  File "/Users/adair-jie/PythonProject/imoocc/scanhosts/util/j_filter.py", line 31, in run

    self.filter_type()

  File "/Users/adair-jie/PythonProject/imoocc/scanhosts/util/j_filter.py", line 98, in filter_type

    VirtualServerInfo.objects.create(server_ip=item_val[0],server_type=item_val[-1],system_ver=item_val[6],sys_hostname=item_val[7],mac=item_val[-3],sn=item_val[-2],vir_phy_id=1,conn_vir_id=int(self.key_sn_relate[sn_key]))

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method

    return getattr(self.get_queryset(), name)(*args, **kwargs)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/query.py", line 348, in create

    obj.save(force_insert=True, using=self.db)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/base.py", line 710, in save

    force_update=force_update, update_fields=update_fields)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/base.py", line 738, in save_base

    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/base.py", line 822, in _save_table

    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/base.py", line 861, in _do_insert

    using=using, raw=raw)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method

    return getattr(self.get_queryset(), name)(*args, **kwargs)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/query.py", line 920, in _insert

    return query.get_compiler(using=using).execute_sql(return_id)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql

    cursor.execute(sql, params)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute

    return super(CursorDebugWrapper, self).execute(sql, params)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute

    return self.cursor.execute(sql, params)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__

    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute

    return self.cursor.execute(sql, params)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute

    return self.cursor.execute(query, args)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute

    self.errorhandler(self, exc, value)

  File "/Users/adair-jie/virtualenv/imoocc/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler

    raise errorclass, errorvalue

django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`imoocc`.`virtualserverinfo`, CONSTRAINT `virtualserv_vir_phy_id_23beab5c45b1088b_fk_physicalserverinfo_id` FOREIGN KEY (`vir_phy_id`) REFERENCES `physicalserverinfo` (`id`))')


写回答

2回答

weibo_巧客叔叔_0

2018-04-13

我也遇到了这种情况,是这样解决的

需要在setting文件的databases中添加以下代码取消外键检查

'OPTIONS': {"init_command":"SET foreign_key_checks = 0;"},

具体可参考https://blog.csdn.net/qingche456/article/details/58153741


2
1
十万伏特_皮卡丘
非常感谢!
2018-05-12
共1条回复

Jeson

2018-03-02

应该还是有数据没有写入,看下physicalserverinfo这张表格中的信息是否有对应记录。

这种情况的出现,可能还是环境中存在不一致的地方导致。

建议把执行过程中,获取到的结果一步步打印出来进行排错。


0
0

Python+Django+Ansible Playbook自动化运维项目实战

【课程升级3.6版本】大牛全面践行DevOps,运维与开发间高效协作

861 学习 · 326 问题

查看课程