0

First python script and I'm getting an error I can't seem to get around using a config file. The first part of the script takes user input and puts that into a mysql database with no problem..Then I get to the filesystem work and things go a bit pear shaped..I can get it to work without using the config file options but I'd like to keep it consistent and pull from that file:

  vshare = str(raw_input('Share the user needs access to: '))
  vrights = str(raw_input('Should this user be Read Only? (y/n): '))
  f = open("%s/%s" % (config['vsftp']['user_dir'], (vusername), 'wr'))
  #f = open("/etc/vsftpd_user_conf/%s" % (vusername) , 'wr' )
  f.write("local_root=%s/%s" % (config['vsftp']['local_root_dir'], vshare))
  if vrights.lower() in ['y', 'ye', 'yes']:
      buffer = []
      for line in f.readlines():
          if 'write_enable=' in line:
              buffer.append('write_enable=NO')
          else:
              buffer.append(line)
      f.writelines(buffer)
  f.close()

The error I'm getting is:

TypeError: not all arguments converted during string formatting

If I uncomment the commented line it works and makes it a bit further and errors out as well..But I'll deal with that once I get this hiccup sorted.

5 Answers 5

3

Your tuple is misshaped

f = open("%s/%s" % (config['vsftp']['user_dir'], (vusername), 'wr'))

Should be

f = open("%s/%s" % (config['vsftp']['user_dir'], (vusername)), 'wr')
Sign up to request clarification or add additional context in comments.

1 Comment

That did it...Thanks to all that replied..That was fast!! Ran into the second error which is a bad file descriptor error..Trying to get that one sorted out on my own..Thanks again!
2

The error is here:

open("%s/%s" % (config['vsftp']['user_dir'], (vusername), 'wr'))

You have three parameters, but only two %s in the string. You probably meant to say:

open("%s/%s" % (config['vsftp']['user_dir'], vusername), 'wr')

Although 'wr' is unclear, you probably mean w+ or r+.

http://docs.python.org/library/functions.html#open

Comments

0
f = open("%s/%s" % (config['vsftp']['user_dir'], (vusername), 'wr'))

You are passing three arguments (config['vsftp']['user_dir'], (vusername), 'wr') to a format string expecting two: "%s/%s". So the error is telling you that there is an argument to the format string that is not being used.

Comments

0

I think you have a wrong parenthesis, your line should be:

f = open("%s/%s" % (config['vsftp']['user_dir'], (vusername)), 'wr')

Comments

0

It looks like this line should be:

f = open("%s/%s" % (config['vsftp']['user_dir'], vusername), 'wr')

(I moved the closing parenthesis over.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.