request.get python url-path instead of query argument passing in
<p>I am trying to pass in parameters into my REST API get request, like this:</p>

<p><code>parameters = {'key':value}</code></p>

<p><code>response = requests.get('some url', params= parameters)</code></p>

<p>but the API that I am using uses a url-path instead of a query argument. I want it like:</p>

<p><code>/api/resource/parametervalue</code></p>

<p>and it comes out like:</p>

<p><code>/api/resource?parameter=value</code></p>

<p>I've searched all over the web to find if I can somehow change what response.get takes in, but I can't seem to find it. What should I do?</p>

<p>Thank you!</p>

<p>The <code>params</code> optional argument will prepend a <code>?</code> before the query string as defined in the source code <a href="https://github.com/kennethreitz/requests/blob/master/requests/models.py#L69" rel="nofollow" title="here">here</a>.</p>

<p>You're better off modifying the URL before you call <code>requests.get</code></p>

<pre><code>&gt;&gt;&gt; parameters = ('param', 'value')
&gt;&gt;&gt; base_url = 'http://host/api/resource'
&gt;&gt;&gt; query = ''.join((parameters[0], parameters[1]))
&gt;&gt;&gt; url = '/'.join((base_url, query))
</code></pre>

<p>So <code>url</code> becomes:</p>

<pre><code>&gt;&gt;&gt; url
'http://host/api/resource/paramvalue'
&gt;&gt;&gt; response = requests.get(url)
</code></pre>

<p>If you have different paths in the same host that you use at different times you could even break down <code>base_url</code> into <code>host</code> and <code>path</code> and then join <code>host</code>, <code>path</code> and <code>query</code>. Remember the <code>join</code> method takes just one iterable argument.</p>

python rest api get