How do you do string interpolation with a URL that contains formating characters?
<p>I'm trying to use URLLIB2 to open a URL and read back the contents into an array. The issue seems to be that you cannot use string interpolation in a URL that has formating characters such as %20 for space, %3C for '&lt;'. The URL in question has spaces and a bit of xml in it.</p>

<p>My code is pretty simple, looks something like this:</p>

<pre><code>#Python script to fetch NS Client Policies using GUID

import sys
import urllib2

def GetPolicies(ns, guid):
    ns = sys.argv[1]
    guid = sys.argv[2]
    fetch = urllib2.urlopen('http://%s/Altiris/NS/Agent/GetClientPolicies.aspx?xml=%3Crequest%20configVersion=%222%22%20guid=%22{%s}%22') % (ns, guid)
</code></pre>

<p>I've shortened the URL for brevity but you get the general idea, you get a 'Not enough arguments for format string' error since it assumes you're wanting to use the %3, %20, and other things as string interpolations. How do you get around this?</p>

<h1>Edit: Solution requires Python 2.6+, 2.5 or prior has no support for the string.format() method</h1>
