Need to get the destination(success/failure) details of Lambda function using get_function_event_invoke_config boto3 function.
response = client.get_function_event_invoke_config(
FunctionName='sample'
)
for item in response:
rpt = item(['DestinationConfig'])
But I am getting an error
'str' object is not callable.
Could you please provide the code snippet for this requirement.
Related
I want to get transaction details using Solana API with python. There are two documents for it.
1: https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
2: https://michaelhly.github.io/solana-py/rpc/api/#solana.rpc.api.Client.get_transaction
I used this code below
solana_client = Client("https://api.mainnet-beta.solana.com")
from solders.signature import Signature
sig = Signature.from_string("3NHUEPkc7a2mPkC51umAbLdNjrwoEaCXfdJ7BjHaEhYPchy5TtrCifbJqSujyZCNRuDKDfJvpN8osx9KvSWdwMp8")
solana_client.get_transaction(sig).value.block_time
and I got multiple errors
TypeError: Object of type Signature is not JSON serializable
TypeError: dict had unencodable value at keys: {params: because (list had unencodable value at index: [0: because (Object of type Signature is not JSON serializable)])}
TypeError: Could not encode to JSON
Any idea how can i handle this error?
I received a JSON object via MQTT in a react.js app. I can clearly see that the power value exists but nevertheless, I get the exception from the question title. I assume I wrongly access the JSON but how should I access it?
How the JSON object looks:
Here is how I do it now:
// this is one component where I receive it
let decodedMessage = JSON.parse(message);
//power component where I am supposed to receive it
const {portside} = this.props
const power = portside.power
I want to receive a json string as a response from a REST API URL.
It has
header as Content-Type=application/json.
It should have a body with json format
eg-{"string1":"string2","string3":"string4"}
These are the details I am inputting when using POSTMAN. What is the correct Syntax for the above requirement.
I am trying the following syntax but it always throws an error:
POST(url = login,add_headers('Content-Type'='application/json'),body = c("string1"="string2","string3"="string4"),encode = c("json"),verbose())
Try using this
POST(url = login,add_headers('Content-Type'='application/json'),body = list(string1="string2",string3="string4"),encode = "json",verbose())
I'm getting the following error when trying to parse a json response
expected string or buffer
Within my Django model I have the following:
def get_batch_prediction(self):
client = boto3.client('machinelearning', region_name=settings.region, aws_access_key_id=settings.aws_access_key_id, aws_secret_access_key=settings.aws_secret_access_key)
return client.get_batch_prediction(
BatchPredictionId=str(self.id)
)
I then call it like so
batch = BatchPrediction.objects.get(id=batch_id)
response = batch.get_batch_prediction()
response = json.loads(response)
I know the response is json so I expected this to change it to a dictionary but, instead, I get the error above.
What's going on?
The boto3 docs suggest that get_batch_prediction returns a dictionary not a string. You shouldn't have to use json.loads().
I am trying to read json response from this link. But its not working! I get the following error:
ValueError: No JSON object could be decoded.
Here is the code I've tried:
import urllib2, json
a = urllib2.urlopen('https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=https://www.economicalinsurance.com/en/&strategy=mobile&filter_third_party_resources=false&callback=_callbacks_._DElanZU7Xh1K')
data = json.loads(a)
I made these changes:
import requests, json
r=requests.get('https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=https://www.economicalinsurance.com/en/&strategy=mobile&filter_third_party_resources=false')
json_data = json.loads(r.text)
print json_data['ruleGroups']['USABILITY']['score']
A Quick question - Construct Image link .
I able to get here : -
from selenium import webdriver
txt = json_data['screenshot']['data']
txt = str(txt).replace('-','/').replace('_','/')
#then in order to construct the image link i tried : -
image_link = 'data:image/jpeg;base64,'+txt
driver = webdriver.Firefox()
driver.get(image_link)
The problem is i am not getting the image, also the len(object_original) as compared len(image_link) differs . Could anybody please advise the right elements missing in my constructed image link ?. Thank you
Here is API link - https://www.google.co.uk/webmasters/tools/mobile-friendly/ Sorry added it late .
Two corrections need to be made to your code:
The url was corrected (as mentioned by Felix Kling here). You have to remove the callback parameter from the GET request you were sending.
Also, if you check the type of the response that you were fetching earlier you'll notice that it wasn't a string. It was <type 'instance'>. And since json.loads() accepts a string as a parameter variable you would've got another error. Therefore, use a.read() to fetch the response data in string.
Hence, this should be your code:
import urllib2, json
a = urllib2.urlopen('https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=https://www.economicalinsurance.com/en/&strategy=mobile&filter_third_party_resources=false')
data = json.loads(a.read())
Answer to your second query (regarding the image) is:
from base64 import decodestring
arr = json_data['screenshot']['data']
arr = arr.replace("_", "/")
arr = arr.replace("-","+")
fh = open("imageToSave.jpeg", "wb")
fh.write(str(arr).decode('base64'))
fh.close()
Here, is the image you were trying to fetch - Link
Felix Kling is right about the address, but I also created a variable that holds the URL. You can try this out to and it should work:
import urllib2, json
url = "https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=https://www.economicalinsurance.com/en/&strategy=mobile&filter_third_party_resources=false"
response = urllib2.urlopen(url)
data = json.loads(response.read())
print data