×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    17

    Problem with ConfigObject

    Hi All,

    I am writing a python script which is basically connecting to a web site using userid and password.I am getting all the site and login information from a configuration file.Inorder to access those parameters I have used ConfigObject.But when I run that program I am getting the error
    import ConfigObj
    ImportError: No module named ConfigObj

    Can anyone please help me in this regard???

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Problem with ConfigObject

    Hi lalithak85 and welcome to the Python Discussion Board.

    I'm not entirely sure I understand your problem so I apologise if what I'm about to say doesn't help.

    From what I've learned right now using Google, ConfigObj lets you read config files. I've also learned that it is a separate file that doesn't come with Python, so it clearly doesn't come with PyS60.

    So your error is most likely due to the fact that you didn't have the configobj.py file. Try copying it to your phone (or appropriate location in the emulator if you're using one) and add this to the code before "import ConfigObj":
    Code:
    import sys
    sys.path.append("C:\\")
    #Note that I used C:\ as an example. You should specify the path to configobj.py
    Hope that helps
    Last edited by bogdan.galiceanu; 2008-04-30 at 13:09.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    17

    Re: Problem with ConfigObject

    Hi Bogdan,
    Thanks for ur reply..I have tried that.But It is still showing that error..
    Below is the code which i wrote
    import re
    #from mechanize import Browser
    #from mechanize import FormFiller
    #from URI import URL
    import sys
    sys.path.append('C:\\configobj.py')
    from configobj import ConfigObj


    print "------------------------------------------------------------------------.\n\
    Extracting users (user_id, login_name, email, real name, organization)\n";
    #cfg=ConfigParser.ConfigParser()
    #cfg.read("csd200a-mech.ini")
    cfg = ConfigObj("csd200a-mech.ini")
    site_id=cfg["site_id"]
    admin_id=cfg["admin_id"]
    admin_passwd=cfg["admin_passwd"]
    print "$site_id"
    print "$admin_id"
    print "$admin_passwd"

    Please help me in this regard.

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Problem with ConfigObject

    Okay, first please use the CODE tags when posting code to make it easier to read and keep indentation. Just write ["code"] and ["/code"] (without the quotes) around the code.

    The first problem I see is that you wrote
    Code:
    sys.path.append('C:\\configobj.py')
    I meat specify the path up until the file. So that would be:
    Code:
    sys.path.append('C:\\')
    
    #To show what I mean, if the file was located at E:\myfolder\configobj.py, you would have to write:
    
    sys.path.append('E:\\myfolder')
    Please try it now and let us know of the result.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    17

    Re: Problem with ConfigObject

    Hi Bogdan,
    Yep It worked Thanks a lot!!!!I have another doubt.
    In perl we have something like www:mechanize to interact with web sites.Is there any equivalent one in python???

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Problem with ConfigObject

    I'm not too skilled with web pages, especially when it comes to manipulating them with Python. But I can tell you that urllib is a useful module when it comes to things like this.
    It would be a good idea to wait for someone more competent in this domain to answer this question.

    Glad I was able to help so far

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Re: Problem with ConfigObject

    Hello

    I have an .ini (settings file) which contains following:

    Code:
    [section1]
    item1=value
    item2=value
    
    [section2]
    item3=value
    I put the "test.ini" and the "configobj.py" files in "E:\".

    I then run the following script (iniread.py):

    Code:
    import sys
    sys.path.append("E:\\")
    import configobj
    from configobj import ConfigObj
    
    config = ConfigObj("test.ini")
    
    section = config['section2']
    value = section['item3']
    
    print 'item3 : ' + value
    But I get the following error:

    Traceback (most recent call last):
    File "C:\private\2000b1a5\default.py", line 81, in menu_action
    f()
    File "C:\private\2000b1a5\default.py", line 65, in query_and_exec
    execfile(script_list[index][1]. encode('utf-8'), script_namespace. namespace)
    File "C:\python\iniread.py", line 8, in ?
    section = config['section2']
    File "E:\configobj.py", line 580, in __getitem__
    val = dict.__getitem__(self, key)
    KeyError: section2
    What do I get wrong? I don't understand :\

    I also want to know how to read a file that is not in the same folder as configobj.py I tried with E:\\foldername\test.ini but I got a parse error in configobj.py...
    Last edited by Take0n; 2008-08-20 at 20:59.

Similar Threads

  1. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  2. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  3. WAP service problem on Apache
    By bigg_o in forum Browsing and Mark-ups
    Replies: 3
    Last Post: 2005-04-17, 16:05
  4. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •