Skip to content
Advertisement

Don’t understand this ConfigParser.InterpolationSyntaxError

So I have tried to write a small config file for my script, which should specify an IP address, a port and a URL which should be created via interpolation using the former two variables. My config.ini looks like this:

[Client]
recv_url : http://%(recv_host):%(recv_port)/rpm_list/api/
recv_host = 172.28.128.5
recv_port = 5000
column_list = Name,Version,Build_Date,Host,Release,Architecture,Install_Date,Group,Size,License,Signature,Source_RPM,Build_Host,Relocations,Packager,Vendor,URL,Summary

In my script I parse this config file as follows:

config = SafeConfigParser()
config.read('config.ini')
column_list = config.get('Client', 'column_list').split(',')
URL = config.get('Client', 'recv_url')

If I run my script, this results in:

Traceback (most recent call last):
  File "server_side_agent.py", line 56, in <module>
    URL = config.get('Client', 'recv_url')
  File "/usr/lib64/python2.7/ConfigParser.py", line 623, in get
    return self._interpolate(section, option, value, d)
  File "/usr/lib64/python2.7/ConfigParser.py", line 691, in _interpolate
    self._interpolate_some(option, L, rawval, section, vars, 1)
  File "/usr/lib64/python2.7/ConfigParser.py", line 716, in _interpolate_some
    "bad interpolation variable reference %r" % rest)
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'

I have tried debugging, which resulted in giving me one more line of error code:

...
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7fc4d32c46e0> ignored

Here I am stuck. I don’t know where this _remove function is supposed to be… I tried searching for what the message is supposed to tell me, but quite frankly I have no idea. So…

  1. Is there something wrong with my code?
  2. What does ‘< function _remove at … >’ mean?

Advertisement

Answer

There was indeed a mistake in my config.ini file. I did not regard the s at the end of %(...)s as a necessary syntax element. I suppose it refers to “string” but I couldn’t really confirm this.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement