简体   繁体   中英

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?

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM