Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Fix AttributeError: module 'botocore.vendored.requests' has no attribute 'Post' Traceback

I'm trying to get my LexBot to communicate with Lambda so I followed the process for creating the request, signature and everything needed to do so. But I am not sure if I need to import certain things from Python. It fails when I'm about to post the message. The signature is created as well as the auth header.

Please advise guys, Any help will be appreciated!

I've used these articles as guidelines: https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html

https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

print ('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print ('Request URL = ' + endpoint)
print('\n' + authorization_header)
print('\nX-Amz-content-Sha256 header is' + payload_hash)

r = requests.Post ('myendpoint'+ canonical_uri, data=payload, 
headers=headers)
data = r.json()
lex_message = data['message']
print ('' + lex_message)

So I assume my problem is coming from this piece of code, N.b I removed my endpoint.

Also not sure what goes into data in request.

like image 929
Jose' Avatar asked Aug 14 '19 13:08

Jose'


1 Answers

I had the same error but for GET using python3.8. Support for GET/POST has already been removed from botocore.vendored.requests in python3.8.

As a workaround, you can use python3.7 for your lambda and it will still work for a while. However you will be getting a warring that support for this will be removed on 2020/03/31 as well:

DeprecationWarning: You are using the put() function from 'botocore.vendored.requests'.  This dependency was removed from Botocore and will be removed from Lambda after 2020/03/31. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.put() function instead.

So there is not much choice as to use pip to get requests package, or use layer as shown in the link below.

More information can be found in Upcoming changes to the Python SDK in AWS Lambda

like image 189
Marcin Avatar answered Oct 29 '22 14:10

Marcin