I am trying to encode a json parameter within a url for use with the mongolab restAPI. 

My url looks something like this

```
url = 'https://api.mongolab.com/api/1/databases/db/collections/coll?q={"q": "10024"}&apiKey=mykey 

```

I am trying to open it using

```
urllib2.urlopen(url)

```

but I run into errors saying that my apikey is incorrect. I know this isn't true because if I copy and paste the url into my browser I get a correct response. I also know that I can access the rest api as long as I don't have the query there (so it must be a json/formatting problem). 

So does anyone know how I could encode the json query

```
{"q": "10024"} 

```

into the url? Thanks!