我正在调试 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()
是错的...你有什么主意吗...?我将不胜感激任何帮助!
谢谢你。
最佳答案
我也在处理这个错误。我尝试使用 browser.close() 方法,虽然它确实阻止了 - 'NoneType' 对象没有属性 'path' - 被显示,我留下了一堆打开的 Firefox 浏览器实例。
.close() 方法关闭 chrome,它不会在 firefox 中抛出 NoneType 错误,但它会让 firefox 保持打开状态。 .quit() 方法关闭两个浏览器,但它会为 firefox 抛出错误。
我正在为我的代码使用 django 的 StaticLiveServerTestCase 类。
我写了一个小调试器循环来测试。只需取消注释并注释掉 .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()
我仍然不知道答案,但我认为这是朝着正确方向迈出的一步。
关于python-2.7 - 异常属性错误 : "' NoneType' object has no attribute 'path' "in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38574821/