Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a put request using urllib3

I am trying to make a put request in AWS lambda. Requests does not comes by default in the python lambda runtime (I know it can be installed using pip and uploading a zip file but this is not what I want.), and requests from botocore is going to get retired soon, so I the only thing I have left is urllib3.

This is how I would do normally using the requests module:

import requests
response_body = {'Status': 'SUCCESS',
    'Reason': 'whatever'}
requests.put(url, data=json.dumps(response_body))

How can I do the same using urllib3?

like image 440
Simon Ernesto Cardenas Zarate Avatar asked Nov 28 '25 23:11

Simon Ernesto Cardenas Zarate


1 Answers

I guess it was pretty similar:

import urllib3
http = urllib3.PoolManager()

response_body = {'Status': 'SUCCESS',
  'Reason': 'whatever'}
r = http.request('PUT', event['ResponseURL'],body=json.dumps(response_body))
like image 126
Simon Ernesto Cardenas Zarate Avatar answered Nov 30 '25 12:11

Simon Ernesto Cardenas Zarate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!