Putting a literal encoded + in the request without it encoding.

I have to connect to a searching feature, amongst many other features, and I have so far been able to do it easily with one command with python requests.
However, when I use the search I need to send one parameter with +'s in it.
This person has this same issue...
http://stackoverflow.com/questions/12527959/passing-the-character-in-a-post-request-in-python
But I feel it's a bit silly considering I am using requests so heavily here.

``` python
def send_message(command, payload = {}):
    command_version = {'offers': "2.1", 'categories': '1.0'}
    url = BASE_URL + "/" + command_version[command] + "/" + command
    headers = {"X-Apikey":API_KEY}
    return requests.get(url, params = payload, headers=headers)

send_message('offers', payload={'searchword':search_term, 'limit':page_size+1, 'offset':offset*page_size, "deleted":0}).json()['offers']
```

As you can see in calling the method, search_term will have text like this:
"one+2+three"
but the message is encoded as stated in the stackoverflow link I posted.
Is there a way I can stop the encoding of the + without having to create a new messaging system just for searches?


There are a number of options, but the easiest thing to do is probably to use the [`PreparedRequest`](http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests) flow. Building the `PreparedRequest` will let you arbitrarily mutate its encoded `r.url` property, and you can then use the tools in `urllib` to make whatever changes you need to make, or indeed to entirely rebuild it as suggested in Marijn's SO answer.


Do you mean like this?

``` python
def send_message(command, payload = {}):
    import urllib
    command_version = {'offers': "2.1", 'categories': '1.0'}
    url = OIKIAN_URL + "/" + command_version[command] + "/" + command
    headers = {"X-Apikey":API_KEY}

    from requests import Request, Session
    s = Session()
    if "searchword"  in payload:
        print "found search word... Trying to properly encoding it."
        payload['searchword'] = urllib.quote(payload['searchword'], safe='+')
    req = Request('GET', url,
        params = payload,
        headers = headers
    )
    prepped = req.prepare()
    # do something with prepped.body
    # do something with prepped.headers
    return s.send(prepped)
```

It seems to have the same effect. Sadly.
Any idea what I am doing wrong and why?


I did not mean like that, I meant manipulating the URL _after_ the call to `req.prepare()`.


Ah yes.... to be clear, here was my solution.

``` python
def send_message(command, payload = {}):
    import urllib
    command_version = {'offers': "2.1", 'categories': '1.0'}
    url = OIKIAN_URL + "/" + command_version[command] + "/" + command
    headers = {"X-Apikey":API_KEY}

    from requests import Request, Session
    s = Session()
    req = Request('GET', url,
        params = payload,
        headers = headers
    )
    prepped = req.prepare()
    prepped.url =  (prepped.url).replace("%2B", "+")
    return s.send(prepped)
```

It's too bad I can't define that information when passing the params.  That would be much cleaner than this. Perhaps:

``` python
r = requests.get('https://api.example.com/test', params = cheese_dict, safe="+" )
```

And it would only apply that to params.
You probably know best.
Thanks!


Yeah, sorry, but our position is that we support the 90% use-case. This allows us to keep our API clean and clear. Every use-case in the remaining 10% we want to make _possible_, but we won't accept API extensions for.


Totally understandable.  Thank you.