3

I'm new to Python and am trying my first applications. Why am I getting the Attribute message:

Traceback (most recent call last): File "C:\Users\myname\documents\visual studio 2010\Projects\PythonApplication 1\PythonApplication1\RunSikuliOnVM.py", line 97, in logging.config.dictConfig(LOG_DICT_CONFIG_OnVM) AttributeError: 'module' object has no attribute 'config' Press any key to continue . . .

Here is a portion of my code so far:

import os
import sys
import subprocess
import fnmatch
import datetime
import logging
import logging.handlers
import logging.config

"""===Global Variables==="""

LOGFILE = r"V:/RunTests.log"
LOGDETAILS= r"V:/SikuliScriptDetails.log"
FAILEDTESTS = r"V:/FailedTests.txt"

"""Logging configuration"""
#   Dictionary configuration for logging within RunSikuliOnVM.py
LOG_DICT_CONFIG_OnVM = {
    'version': 1,              
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
        'format': '%(levelname)-8s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'

    },
    'standard': {
        'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'

    },
    'simple': {
        'format': '%(asctime)s %(levelname)-8s %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'
    }
},
'handlers': {
    'console': {
        'level':'DEBUG',    
        'class':'logging.StreamHandler',
        'formatter': 'simple'
    },
    'RunTests_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'simple',
        'filename': LOGFILE,
        'when':'D',
        'interval': 7, 
        'backupCount':1, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    },
    'SikuliScriptDetails_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'verbose',
        'filename':LOGDETAILS,
        'when':'D',
        'interval': 7, 
        'backupCount':2, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    },
    'FailedTests_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'standard',
        'filename':FAILEDTESTS,
        'when':'D',
        'interval': 7, 
        'backupCount':2, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    }
},
'loggers': {
    'RunTests_Logger': {                  
        'handlers': ['RunTests_Handler'],        
        'level': 'DEBUG',  
        'propagate': False  
    },
    'SikuliScriptDetails_Logger': { 
        'handlers': ['SikuliScriptDetails_Handler'],
        'level': 'DEBUG',  
        'propagate': False 
    },
    'FailedTests_Logger': {
        'handlers': ['FailedTests_Handler'],
        'level': 'DEBUG',
        'propagate': False
    }
}
}

logging.config.dictConfig(LOG_DICT_CONFIG_OnVM)

logfilelogger = logging.getLogger('RunTests_Logger')
logdetailslogger = logging.getLogger('SikuliScriptDetails_Logger')
failedtestslogger = logging.getLogger('FailedTests_Logger')

PS: Some of the indentation is off...

5
  • 6
    This error only occurs for me when import logging.config is not included in the file. Is this included in the code that you are running?
    – FMcC
    Aug 7, 2013 at 19:23
  • 1
    Yes it is. As you can see in my code snippet, I have all three: import logging import logging.handlers import logging.config
    – Alain
    Aug 7, 2013 at 19:50
  • I see that it's there in that snippet, but is it possible that visual studio is running a previous (cached?) version of the file? Have you tried without the import logging? I can run it without and i'm not sure that the top level module is being called.
    – FMcC
    Aug 7, 2013 at 19:52
  • Oh, I think I see what you mean about the possibility of another cached version running. This module you see in the snippet is actually a child process of another module. The parent module also has import logging in it. Do you think I should delete the one in the child process?
    – Alain
    Aug 7, 2013 at 21:13
  • I'm not sure what you mean by a parent and child process (two seperate python modules? parent.py and child.py?) What happens when you try without the import logging in the child process? The error message indicates that it's trying to use a config attribute in the logging module, not logging.config.
    – FMcC
    Aug 7, 2013 at 21:25

1 Answer 1

2

I'm also a newbie. I had the same problem. I deleted the crud in my directory (build and dist folders etc), then rebuilt it all. Bingo! I suspect that, as Alain suggested, PyCharm has cached something undesirable.

3
  • Oh the things that will crash just because you have more than you need!
    – Alain
    Feb 12, 2014 at 22:13
  • Just in case anyone using PyCharm is here wondering how to clean the cache of their interpreter, the answer is here, Please check and let us know if that solved your problem.
    – Alain
    Oct 24, 2017 at 19:19
  • 1
    I also just started a blog entry to investigate the issue a little further and gather documentation about it all in one place.
    – Alain
    Oct 24, 2017 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.