title: Python "requests" vs "urllib3" to AWS API Gateway
body: <p>I am writing a python program that calls AWS API Gateway to reach dynamoDB.</p>
  <p>And it all works fine when I use python &quot;requests&quot;:
  r = requests.post(&quot;https://xxxxxxx.execute-api.us-east-1.amazonaws.com/Prod/log-entries&quot;,
  data={'logbookTimestamp': timestamp, 'Name': &quot;Fred&quot;})</p>
  <p>Now in order to run this as a lambda function, I want to use &quot;urllib3&quot; instead of &quot;requests&quot;
  because urllib3 is included by default in lambda's python. So now I am trying to do the same with urllib3 but can't get it to work. I've read the urllib3 user guide here (<a href="https://urllib3.readthedocs.io/en/latest/user-guide.html#json" rel="nofollow noreferrer">https://urllib3.readthedocs.io/en/latest/user-guide.html#json</a>) and it says I need to encode the JSON data before sending it so I've done this:</p>
  <pre><code>http = urllib3.PoolManager()
  fields = {'logbookTimestamp': timestamp, 'Name': &quot;Fred&quot;}
  encoded_fields = json.dumps(fields).encode('utf-8')
  link = &quot;https://xxxxxxx.execute-api.us-east-1.amazonaws.com/Prod/log-entries&quot;
  r = http.request('POST',
                   link,
                   body=encoded_fields,
                   headers={'Content-Type': 'application/json'}
                   )
  </code></pre>
  <p>When I look at the output of both in CloudWatch I see that the data are formatted differently.</p>
  <p>With requests:
  (c084a37e-43d8-464a-9dcf-e40c28922ece) Method request body before transformations: logbookTimestamp=2020%3A12%3A15%3A20%3A11%3A02&amp;Name=Fred</p>
  <p>With urllib3:
  (9b8d84e9-2403-462c-b25f-945a927d1e66) Method request body before transformations:
  {
  &quot;logbookTimestamp&quot;: &quot;2020:12:15:21:31:21&quot;,
  &quot;Name&quot;: &quot;Fred&quot;
  }</p>
  <p>and returns the following:
  (9b8d84e9-2403-462c-b25f-945a927d1e66) Endpoint response body before transformations:
  {
  &quot;statusCode&quot;: 500,
  &quot;headers&quot;: {
  &quot;Content-Type&quot;: &quot;text/html; charset=utf-8&quot;,
  &quot;Content-Length&quot;: &quot;290&quot;
  },
  &quot;body&quot;: &quot;\n500 Internal Server Error\n<h1>Internal Server Error</h1>\n<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n&quot;
  }
  (9b8d84e9-2403-462c-b25f-945a927d1e66) Endpoint response body before transformations: {&quot;statusCode&quot;: 500, &quot;headers&quot;: {&quot;Content-Type&quot;: &quot;text/html; charset=utf-8&quot;, &quot;Content-Length&quot;: &quot;290&quot;}</p>
  <p>I can't figure out how to get the data in the format in &quot;urllib3&quot; that will be accepted like it is with &quot;requests&quot;. Any thoughts? Thanks!</p>