I\'m running the following code:
asset = {} asset[\'abc\'] = \'def\' print type(asset) print asset[\'abc\'] query = \'{\"abc\": \"{abc}\"}\'.format(abc=asset
The topmost curly braces are interpreted as a placeholder key inside your string, thus you get the KeyError. You need to escape them like this:
KeyError
asset = {} asset['abc'] = 'def' query = '{{"abc": "{abc}"}}'.format(**asset)
And then:
>>> print query {"abc": "def"}