Exception AttributeError: "'NoneType' object has no attribute 'path'" in
Exception AttributeError: "'NoneType' object has no attribute 'path'" in
我正在调试 python 代码 (python2.7.12),因为我的代码可以正常工作,但在将推文流式传输到数据库时,所有变量都为 NULL。
我得到的错误是:
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored
我假设此错误来自以下代码:
def put_tweets_in_database(tweets):
print "putting tweets in database"
errors = 0
count = 0
for tweet in tweets:
try:
commit_tweet_to_database(tweet, count, len(tweets))
count += 1
except Exception as e:
print e
session.rollback()
errors += 1
print 'there were {} errors'.format(errors)
我不认为函数 commit_tweet_to_database()
是错误的...
你有什么想法...?如果有任何帮助,我将不胜感激!
谢谢。
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored
这表明在函数 _remove
中试图访问 NoneType
对象上的属性 path
。 NoneType
对象没有属性。因此,您可能需要查看 _remove
函数并从那里开始调试。
我有同样的错误,这是我的情况:
浏览器 = webdriver.Firefox()
browser.get('http://www.google.com')
打印browser.title
- 以下将给我错误消息:'NoneType' object has no attribute 'path'
browser.quit()
- 下面这个不会报错
browser.close()
所以问题是你为你的对象使用了错误的方法!
我也在处理这个错误。我尝试使用 browser.close() 方法,虽然它确实停止了 - 'NoneType' object has no attribute 'path' - 从显示中,我留下了一堆打开的 firefox 浏览器实例.
.close() 方法关闭 chrome,它不会在 firefox 中抛出 NoneType 错误,但它使 firefox 保持打开状态。 .quit() 方法关闭两个浏览器,但它会抛出 firefox 的错误。
我正在为我的代码使用 django 的 StaticLiveServerTestCase class。
我写了一个小的调试器循环来测试一下。只需取消注释并注释掉 .quit() 和 .close() 语句即可。
class BaseTestCase(StaticLiveServerTestCase):
@classmethod
def setUp(self):
self.firefox = webdriver.Firefox()
self.chrome = webdriver.Chrome()
self.browsers = [self.firefox, self.chrome]
@classmethod
def tearDown(self):
for browser in self.browsers:
if browser == self.firefox:
print('firefox')
browser.close()
# browser.quit()
elif browser == self.chrome:
print('chrome')
browser.close()
# browser.quit()
我仍然不知道答案,但我认为这是朝着正确方向迈出的一步。
听起来好像您的 "try" 子句失败了,导致打印异常?我可能会向 Exception catch 添加更多调试,例如打印出 commit_tweet_to_database 的参数,只是为了确保您传递了可行的参数。
尝试删除这行代码:
import pdb;pdb.set_trace()
猜想脚本已经调用 pdb.set_trace()
而您正试图覆盖它。这可能是问题的原因。
我正在调试 python 代码 (python2.7.12),因为我的代码可以正常工作,但在将推文流式传输到数据库时,所有变量都为 NULL。
我得到的错误是:
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored
我假设此错误来自以下代码:
def put_tweets_in_database(tweets):
print "putting tweets in database"
errors = 0
count = 0
for tweet in tweets:
try:
commit_tweet_to_database(tweet, count, len(tweets))
count += 1
except Exception as e:
print e
session.rollback()
errors += 1
print 'there were {} errors'.format(errors)
我不认为函数 commit_tweet_to_database()
是错误的...
你有什么想法...?如果有任何帮助,我将不胜感激!
谢谢。
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored
这表明在函数 _remove
中试图访问 NoneType
对象上的属性 path
。 NoneType
对象没有属性。因此,您可能需要查看 _remove
函数并从那里开始调试。
我有同样的错误,这是我的情况:
浏览器 = webdriver.Firefox()
browser.get('http://www.google.com')
打印browser.title
- 以下将给我错误消息:'NoneType' object has no attribute 'path'
browser.quit()
- 下面这个不会报错
browser.close()
所以问题是你为你的对象使用了错误的方法!
我也在处理这个错误。我尝试使用 browser.close() 方法,虽然它确实停止了 - 'NoneType' object has no attribute 'path' - 从显示中,我留下了一堆打开的 firefox 浏览器实例.
.close() 方法关闭 chrome,它不会在 firefox 中抛出 NoneType 错误,但它使 firefox 保持打开状态。 .quit() 方法关闭两个浏览器,但它会抛出 firefox 的错误。
我正在为我的代码使用 django 的 StaticLiveServerTestCase class。
我写了一个小的调试器循环来测试一下。只需取消注释并注释掉 .quit() 和 .close() 语句即可。
class BaseTestCase(StaticLiveServerTestCase):
@classmethod
def setUp(self):
self.firefox = webdriver.Firefox()
self.chrome = webdriver.Chrome()
self.browsers = [self.firefox, self.chrome]
@classmethod
def tearDown(self):
for browser in self.browsers:
if browser == self.firefox:
print('firefox')
browser.close()
# browser.quit()
elif browser == self.chrome:
print('chrome')
browser.close()
# browser.quit()
我仍然不知道答案,但我认为这是朝着正确方向迈出的一步。
听起来好像您的 "try" 子句失败了,导致打印异常?我可能会向 Exception catch 添加更多调试,例如打印出 commit_tweet_to_database 的参数,只是为了确保您传递了可行的参数。
尝试删除这行代码:
import pdb;pdb.set_trace()
猜想脚本已经调用 pdb.set_trace()
而您正试图覆盖它。这可能是问题的原因。