I'm working with Python for AWS Lambda. I have Profile PATCH and Profile DELETE api calls. PATCH request works fine. DELETE returns InternalServerError on
profile_request = ast.literal_eval(str(event['_body']))
PATCH uses the exact same thing. I even tried copy-pasting the line from PATCH to make sure there wasn't a typo. I've seen people say a syntax issue can cause this. I copy-pasted the body from PATCH and replaced profile with archive_status to make sure there wasn't a syntax issue. event is a dictionary. event['_body'] is unicode type. Both requests have the exact same Authorization and Headers requirements. I checked CloudWatch logs to make sure the body is actually listed as _body in the event. I can't figure out why I am getting the InternalServerError for DELETE profile and not PATCH profile. Any suggestions would be appreciated.
PATCH body:
{
"AccessToken": "eyJraWQiOiIzRUZtNG1lRE45c1wvQU9XUGdiYkZJNm1wakVkOVRFR05PYTY0SXJZOWRDdz0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwZTQ1ZDYyZi1mYzQxLTQxNTQtYjZiOC04NjBiNTdkZWNkOGUiLCJkZXZpY2Vfa2V5IjoidXMtZWFzdC0xXzhkYTA3NWQ2LWEzNmItNDZhNS04YjAyLWY3ZmNjY2UxMGZiOCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV96dnNGSkYzRzEiLCJleHAiOjE1MDYzNzI2MjksImlhdCI6MTUwNjM2OTAyOSwianRpIjoiMDU3NTkwMzItYmQ5YS00MzljLWJjM2QtYWY2OGZiZjJmNTBiIiwiY2xpZW50X2lkIjoiNWNscm9vNDhtamZpb2QzaDRoZGgyZDNvZHUiLCJ1c2VybmFtZSI6IjBlNDVkNjJmLWZjNDEtNDE1NC1iNmI4LTg2MGI1N2RlY2Q4ZSJ9.G2-gGYyZajrsAikFPuuttYQAj1Yc7uj-UUz469NEUk0SoEFvcJ3E6MOINmIWYg1W6BwJG09W4C_DvBrbybNZep-T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FcUdTqCBf0TP7kxKp6P2kRRx08PjCqfQX-34XE-YJt2FyIGzSc958OT0MasROdHxr_ozJS6LGHw52BF1UG1llpR3YPGtMe8Gz9Y65RFEIDIpXllShKSFogvy-rdJFnaJqAYYn6WfjtmqDUjYzFTNZmGNOWy7_BxGFX90lUBB0V47k8M4nxvC_qWQ9o1LTkCYXIDD9sWMCtY4ewYmw",
"archive_status": "archive"
}
Sorry. I'm fairly new to python and brand new to json and AWS. Another company setup chalice for deployment and a skeleton of our api with some basic code. I'm supposed to figure it all out and learn how to make it work as my company wants it to. I was testing through postman. The lambda code logger that goes to cloudwatch was how I was tracking down the issue. It turns out the issue was the log line immediately after ast.literal_eval:
profile_request = ast.literal_eval(str(event['_body']))
logger.info(profile_request)
I assumed not seeing that log in cloudwatch meant the ast.literal_eval was the issue. Finding a way to test locally so I could see the trace allowed me to figure out the log line was causing AttributeError: 'dict' object has no attribute 'strip'. That's an easy one so the problem is resolved. Glad I know how to test locally now also. Thank you for replying so quickly.
Related
I have a function which provides a token for a user so they can access a video chat room using the Twilio Video API. Following their docs, we decode a JSON Web Token with the following code to give us their token:
token = AccessToken(ACCOUNT_SID, API_KEY, API_SECRET, identity=f'{request.user.email}')
token.add_grant(VideoGrant(room='My Room'))
context = {
'token': token.to_jwt().decode()
}
This worked perfectly locally, and upon pushing it to live servers, continued to work there without fault. However, a few pushes later, with no changes to this code, and this error (below) has suddenly occurred. This also comes at the same time as another error, which is an ascii encoding error, which I believe may be linked.
It's strange that although no changes have been made to this token object, or the function, that we suddenly encounter this error with decoding this token. If anyone has any pointers, would be greatly appreciated.
PyJWT changed the return type of jwt.encode from bytes to str: https://pyjwt.readthedocs.io/en/stable/changelog.html#jwt-encode-return-type
Solution is to either downgrade/pin the PyJWT package to 1.7.1 or remove the call to decode
context = {
'token': token.to_jwt()
}
I've been testing reading from the Graph API with an app I'm working on for a while. I've been reading events directly from their /{id} endpoints using the Python package. When I attempted this today, however, it didn't work. The response was as follows, when attempted using the Graph API Explorer.
{
"error": {
"message": "Unsupported get request. Object with ID 'XXXXXXXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "HAli25GZ3N4
"
}
}
The Explorer itself seems to know somehow that the object in question is an event, as the field options it gives in the left sidebar are all specific to Event objects. I'm aware you need to go through App Review to be able to read public Events, but I haven't needed to thus far. What's the issue?
I've also checked the changelogs, that state nothing breaking has occured today in that instance. One thing to note was that I was briefly demoted to Moderator of the Page I'm trying to read from. I've tried using my personal Access Token and that of the Page too.
please pardon my lack of understanding with Python, Gmail API, etc.
I'm trying to set up basic functionality to trigger an animation in TouchDesigner, based off whenever a Gmail account receives a new email.
How and where would I make the following code request?
=========================
request = {
'labelIds': ['INBOX'],
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
========================
I've made a separate python file, and it keeps telling me that "name 'labelIDs' is not defined". Am I not importing the correct libraries? Or should there be more defining at the top of the file? I ca't find any examples/tutorials that explain how to best call the watch() function.
Any help would be greatly appreciated
I'm working with Google Directory API (admin sdk) through python and some user updates seem to be doing less than expected. I want to update addresses/emails/...-fields, overwriting the list with an empty one.
I tested in Try it! and even that doesn't work:
The result is 200 OK and everything seem to work until a get-request reviles that nothing has happened.
I just tried to reproduce this and i was able to remove addresses after a few failed attempts.
This is what had to be done in "Try it!"
Switch to the "Freeform Editor". There's a dropdown in the box for the request body.
As request body send
{
"addresses": [{}]
}
Why doesn't it work for you? Since you use the structured editor your request is enclose in double quotes ("") thus the adress is a big mess and nothing happens except you get a really messed up response from the update endpoint. Why in the world google would return a status code 200 (OK) for that evades me.
If you transfer this learning to your code it should work. Sorry i don't grok python so i can't help with the python code.
I'm trying out Tornado's GoogleOAuth2Mixin with the example code shown in the documentation. According to the docs, the function get_authenticated_user "Handles the login for the Google user, returning a user object." (emphasis mine), but the object I receive is a dictionary like so:
{
u'access_token': u'...',
u'expires_in': 3600,
u'id_token': u'...',
u'token_type': u'Bearer'
}
While this is helpful, and I know how to make another HTTP request with the access token to retrieve information about authenticating user, it seems like a bit of a stretch of the imagination to call this dictionary a "user object".
Is this really what I'm supposed to expect, and I'm now meant to go and get the user data myself with another request, or is something going wrong?
This function has never worked as documented, although now that it has existed so long in its current form the documentation, and not the code, will have to change. GoogleOAuth2Mixin.get_authenticated_user returns only the authentication data and you'll have to make a separate request for further details.