Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Python's Requests.session return differently from a regular call?
    primarykey
    data
    text
    <p>I'm working on a piece of code that's using the REST api provided by capsulecrm.com and I'm using python-requests to perform my requests.</p> <p>I tried creating a session object and perform a series of POSTs, the first request returns a 201 but subsequent requests are 302s even when I modify the payload.</p> <pre><code>&gt;&gt;&gt; s = requests.session() &gt;&gt;&gt; s.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [201]&gt; &gt;&gt;&gt; s.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [302]&gt; &gt;&gt;&gt; s.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [302]&gt; </code></pre> <p>However, if I don't create a session and do this the normal way, it returns 201 correctly like so:</p> <pre><code>&gt;&gt;&gt; requests.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [201]&gt; &gt;&gt;&gt; requests.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [201]&gt; &gt;&gt;&gt; requests.post("https://dummy.capsulecrm.com/api/party/12345/history", data=json.dumps(payload), headers=headers,auth=auth) &lt;Response [201]&gt; </code></pre> <p>The document for the REST API is here <a href="http://developer.capsulecrm.com/v1/resources/history/" rel="nofollow">http://developer.capsulecrm.com/v1/resources/history/</a> I would love to use sessions so that I can maintain keep-alive and pre-define all the header data, how do get this to work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload