Transaction REVERT error using Web3.py and local Ganache instance - solidity

Trying to deploy / transact against a local Ganache instance using web3.py. I'm able to read from a deployed contract. I'm also able to read / write through Truffle.
At first I thought it was something wrong with the contract but I still get the same error using an empty contract:
from solcx import compile_source, compile_files
source = '''
pragma solidity >=0.4.22 <0.9.0;
contract TruffleTutorial {
}
'''
compiled_sol = compile_source(
source,
output_values=["abi", "bin-runtime"],
solc_version="0.8.9")
contract_id, contract_interface = compiled_sol.popitem()
bytecode = contract_interface['bin-runtime']
abi = contract_interface['abi']
dummyContract = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.getTransactionCount(Web3.toChecksumAddress(address))+1
txn = dummyContract.constructor().buildTransaction({
"chainId": 1337,
"gasPrice": w3.eth.gas_price,
"from": w3.eth.accounts[0],
"nonce": nonce
})
Error is:
PUSH1
PUSH1
MSTORE
PUSH1
DUP1
REVERT
< {
< "id": 43,
< "jsonrpc": "2.0",
< "error": {
< "message": "VM Exception while processing transaction: revert",
< "code": -32000,
< "data": {
< "stack": "c: VM Exception while processing transaction: revert\n at Function.c.fromResults (/Users/me/some/path/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n at e.exports (/Users/me/some/path/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2089395)",
< "name": "c"
< }
< }
< }

I could've sworn there was no error in the stack trace, but after posting this question I saw a reference to "fill_transaction_defaults" so I added gas like the following and it worked!
txn = dummyContract.constructor().buildTransaction({
"chainId": 1337,
"gasPrice": w3.eth.gas_price,
"gas": 1728712,
"from": w3.eth.accounts[0],
"nonce": nonce })

Related

Client {CLIENT_ID} not found or disabled', 'error_detail_key': 'E20109', 'error_uri': 'https://dev.xing.com/docs/error_responses'}

I am trying to create a monitoring service for Xing. When I try to get de access token with the following request:
consumer = oauth2.Consumer(app_key, app_secret)
client = oauth2.Client(consumer)
...
params = {
"client_id": app_key,
"client_secret": app_secret,
"redirect_uri": app_callback_url,
"code": code,
"grant_type": "authorization_code",
}
_, content = client.request(access_token_url, "POST", body=urllib.parse.urlencode(params))
I get the following response:
{'error': 'invalid_client', 'error_description': 'Client {CLIENT_ID} not found or disabled', 'error_detail_key': 'E20109', 'error_uri': 'https://dev.xing.com/docs/error_responses'}
How can I fix it?
I fixed it by removing the "client_secret" from the parameters and adding the "code_verifier"

Agora start Cloud Recording returns 400 with no error message

I'm trying to set up Cloud Recording for Agora. I'm able to call the acquire method and obtain a Resource ID, but when I try to start recording I get a 400 response that has no error code or reason message. If I change any part of the request body I will get an error code of 2 with a reason message, so I think my request is formatted properly. Also, since the first request to acquire the resource ID is successful, I don't think there should be an authentication issue. The code to generate the RTC Token is being used elsewhere to create the channel and users are able to join channels in the app.
requestBody := fmt.Sprintf(`
{
"cname": "%s",
"uid": "%d",
"clientRequest": {
"token": "%s",
"recordingConfig": {
"maxIdleTime": 30,
"streamTypes": 0,
"channelType": 1,
"transcodingConfig": {
"height": 720,
"width": 1280,
"bitrate": 2260,
"fps": 15,
"mixedVideoLayout": 1,
"backgroundColor": "#000000"
}
},
"storageConfig": {
"vendor": %d,
"region": %d,
"bucket": "%s",
"accessKey": "%s",
"secretKey": "%s",
"fileNamePrefix": ["tracks"]
}
}
}
`, channelID, uid, rtcToken, 1 /*AWS*/, region, os.Getenv("AGORA_BUCKET_NAME"),
os.Getenv("AGORA_BUCKET_ACCESS_KEY"), os.Getenv("AGORA_BUCKET_ACCESS_SECRET"),
channelID)
reqUrl := "https://api.agora.io/v1/apps/" + os.Getenv("AGORA_APP_ID") + "/cloud_recording/resourceid/" + rid + "/mode/mix/start"
req, err := http.NewRequest("POST", reqUrl,
bytes.NewBuffer([]byte(requestBody)))
if err != nil {
return response, err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(os.Getenv("AGORA_CUSTOMER_ID"), os.Getenv("AGORA_CUSTOMER_CERTIFICATE"))
resp, err := httpClient.Do(req)
if err != nil {
return response, err
}
if resp.StatusCode != http.StatusOK {
// this is a 400 with no error code or reason
logger.Log("statuscode", resp.StatusCode)
}
The reason you are able to get a resourceID is because your appID has Cloud Recording enable and a 400 response from start means your request is properly formatted and successfully making the call to start the Agora Cloud Recorder instance but something is causing the Agora Cloud Recorder to fail to start.
Have you tried using the Agora Postman collection to test? I would recommend using it within Postman because it offers a working config that requires you to set your connection credentials into the variables and it should work if your bucket is properly configured.
I wrote this quick-start guide on how to set up Cloud Recording and use the Postman collection to test.

Health Checks UI (BeatPulse) not able to get Teams webhook working

I have an ASP.NET Core 2.2 app that is using health checks and health checks UI. I have that portion working, but when I try to add a webhook for Teams it is not showing up.
I followed the example in the documentation:
"Webhooks": [
{
"Name": "Teams",
"Uri": "https://outlook.office.com/webhook/...",
"Payload": "{\r\n \"#context\": \"http://schema.org/extensions\",\r\n \"#type\": \"MessageCard\",\r\n \"themeColor\": \"0072C6\",\r\n \"title\": \"[[LIVENESS]] has failed!\",\r\n \"text\": \"[[FAILURE]] Click **Learn More** to go to BeatPulseUI Portal\",\r\n \"potentialAction\": [\r\n {\r\n \"#type\": \"OpenUri\",\r\n \"name\": \"Lear More\",\r\n \"targets\": [\r\n { \"os\": \"default\", \"uri\": \"http://localhost:52665/beatpulse-ui\" }\r\n ]\r\n }\r\n ]\r\n}",
"RestoredPayload": "{\"text\":\"The HealthCheck [[LIVENESS]] is recovered. All is up and running\",\"channel\":\"#general\",\"link_names\": 1,\"username\":\"monkey-bot\",\"icon_emoji\":\":monkey_face"
}
],
I tried calling the webhook directly with cURL and this works as expected:
curl -H "Content-Type: application/json" -d "{\"text\": \"Hello World\"}" <YOUR WEBHOOK URL>
I also tried simplifying the Payload:
"Webhooks": [
{
"Name": "Teams",
"Uri": "https://outlook.office.com/webhook/...",
"Payload": "{\"text\":\"[[LIVENESS]] has failed! Failure: [[FAILURE]]\" }",
"RestoredPayload": "{\"text\": \"The HealthCheck [[LIVENESS]] has recovered. \" }"
}
]
Still no joy. When I start up the page I see no webhooks displayed, but I do see this error in the console:
Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at new e.HttpResponse (healthchecks-bundle.js:formatted:473)
at XMLHttpRequest.l.onload (healthchecks-bundle.js:formatted:505)
Which is referring to this:
e.HttpResponse = class {
constructor(A) {
const {status: e, statusText: t, response: a, responseText: n} = A;
this.status = e,
this.statusText = t,
this.response = a || n,
this.data = JSON.parse(this.response) // line 473
}
}
Looking at the network tab I see a call to “healthchecks-webhooks”. The response from this looks like html, but when I go directly to the page it is a json response with the Teams webhook.
Here’s how I’m setting up healthchecks:
.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = HealthChecks.UI.Client.UIResponseWriter.WriteHealthCheckUIResponse
})
.UseHealthChecksUI()
Is there some other configuration I’m missing? How can I get the Teams webhook to work?
The WebHooks.RestoredPayload json doesn't have a closing quote and brace which is causing the parse error.
try this json insetad:
"Webhooks": [
{
"Name": "Teams",
"Uri": "https://outlook.office.com/webhook/...",
"Payload": "{\r\n \"#context\": \"http://schema.org/extensions\",\r\n \"#type\": \"MessageCard\",\r\n \"themeColor\": \"0072C6\",\r\n \"title\": \"[[LIVENESS]] has failed!\",\r\n \"text\": \"[[FAILURE]] Click **Learn More** to go to BeatPulseUI Portal\",\r\n \"potentialAction\": [\r\n {\r\n \"#type\": \"OpenUri\",\r\n \"name\": \"Lear More\",\r\n \"targets\": [\r\n { \"os\": \"default\", \"uri\": \"http://localhost:52665/beatpulse-ui\" }\r\n ]\r\n }\r\n ]\r\n}",
"RestoredPayload": "{\"text\":\"The HealthCheck [[LIVENESS]] is recovered. All is up and running\",\"channel\":\"#general\",\"link_names\": 1,\"username\":\"monkey-bot\",\"icon_emoji\":\":monkey_face\" }"
}
],

Kurento Media Server crashes on start when using certs

I'm using kurento media server 6.6.1 on a Ubuntu 10.4 box in AWS. It runs fine normally, and I'm attempting to use wss, so I uncomment the security lines in /etc/kurento/kurento.conf.json so the file looks like:
{
"mediaServer" : {
"resources": {
// //Resources usage limit for raising an exception when an object creation is attempted
// "exceptionLimit": "0.8",
// // Resources usage limit for restarting the server when no objects are alive
// "killLimit": "0.7",
// Garbage collector period in seconds
"garbageCollectorPeriod": 240
},
"net" : {
"websocket": {
"port": 8888,
"secure": {
"port": 8433,
"certificate": "/etc/letsencrypt/archive/<MYDOMAIN>/fullchain1.pem",
"password": ""
},
//"registrar": {
// "address": "ws://localhost:9090",
// "localAddress": "localhost"
//},
"path": "kurento",
"threads": 10
}
}
}
}
I've also verified that my certs are in the correct location and are valid.
When I restart the service, I get the following output in my /var/log/kurento-media-server/media-server_error.log file, and the service doesn't start (or give any other logs).
kurento-media-server: /usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = boost::log::v2_mt_posix::core; typename boost::detail::sp_member_access<T>::type = boost::log::v2_mt_posix::core*]: Assertion `px != 0' failed.
Aborted (thread 140077491206272, pid 7622)
Stack trace:
[gsignal]
/lib/x86_64-linux-gnu/libc.so.6:0x35428
[abort]
/lib/x86_64-linux-gnu/libc.so.6:0x3702A
[uselocale]
/lib/x86_64-linux-gnu/libc.so.6:0x2DBD7
[__assert_fail]
/lib/x86_64-linux-gnu/libc.so.6:0x2DC82
0x4CC67A at /usr/bin/kurento-media-server
[kurento::kms_init_logging(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)]
/usr/bin/kurento-media-server:0x4EF234
[gst_debug_log_valist]
/usr/lib/x86_64-linux-gnu/libgstreamer-1.5.so.0:0x62EE6
[gst_debug_log]
/usr/lib/x86_64-linux-gnu/libgstreamer-1.5.so.0:0x6303B
[kurento::MediaSet::~MediaSet()]
/usr/lib/x86_64-linux-gnu/libkmscoreimpl.so.6:0xA809B
[std::_Sp_counted_ptr<kurento::MediaSet*, (__gnu_cxx::_Lock_policy)2>::_M_dispose()]
/usr/lib/x86_64-linux-gnu/libkmscoreimpl.so.6:0xB06D2
[std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()]
/usr/lib/x86_64-linux-gnu/libkmscoreimpl.so.6:0xA3916
[__cxa_finalize]
/lib/x86_64-linux-gnu/libc.so.6:0x3A36A
0xA2B53 at /usr/lib/x86_64-linux-gnu/libkmscoreimpl.so.6

Getting video duration does not work in YouTube API v3

I have been using the code below to get the video duration ($vid_dur) using YouTube API v3 since March 2016 and without any problem until it stooped working today without any intervention from my side. Any suggestions?
<?php
$vidkey = "xxxxxxxxx" ;
$apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$vidkey&key=$apikey");
$VidDuration =json_decode($dur, true);
foreach ($VidDuration['items'] as $vidTime)
{
$VidDuration= $vidTime['contentDetails']['duration'];
}
// convert duration from ISO to M:S
$date = new DateTime('2000-01-01');
$date->add(new DateInterval($VidDuration));
$vid_durH= $date->format('H') ;
if ($vid_durH=="00") {
$vid_dur= $date->format('i:s') ;
}
else {
$vid_dur= $date->format('H:i:s') ;
}
?>
Here is part of the error message
Fatal error: Uncaught exception 'Exception' with message
'DateInterval::__construct() [dateinterval.--construct]: Unknown
or bad format ()'
I've tested your code, it is working. I think you are encountering problems with file_get_contents, you might want to use the Google APIs Client Library for PHP as it offers simple, flexible, powerful access to many Google APIs.
Using you request :
Where I set $videokey=UqyT8IEBkvY (24K Magic)
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$vidkey&key=$apikey"
Response:
"items": [
{
"kind": "youtube#video",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/tokAeZifZMO865fU_ytDkWOyIQ0\"",
"id": "UqyT8IEBkvY",
"contentDetails": {
"duration": "PT3M47S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"projection": "rectangular"
}
}
]
Your code :
$VidDuration= "PT3M47S";
$date = new DateTime('2000-01-01');
$date->add(new DateInterval($VidDuration));
$vid_durH= $date->format('H') ;
if ($vid_durH=="00") {
$vid_dur= $date->format('i:s') ;
}
else {
$vid_dur= $date->format('H:i:s') ;
}
echo $vid_dur;
Hope this helps.