Random error in Mumbai: MetaMask - RPC Error: Non-200 status code: '404' - rpc

I'm buidiling a DApp with the Polygon testnet (Mumabi). I need to interact with my smart contract calling some method like in the following script
const web3Modal = new Web3Modal()
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
var tokenContract = new ethers.Contract(nftaddress, NFT.abi ,provider);
const data = await marketContract.fetchItemsCreated()
However, I sometimes get this error
MetaMask - RPC Error: Non-200 status code: '404'
code: -32603
data:
error: "Not Found"
message: "Not Found"
statusCode: 404
I failed to figure out in which case this error occurs: It looks like to be happening random.
I couldn't find any reference to this specific error.
I really appreciate any suggestion

I think the RPC url for deploying smartcontracts is diffrent from RPC url set on metamask wallet for matic mumbai network try to use same RPC url. It solved my issue.

Related

HTTPS request by Axios got 504 error status on the website(live and local) but got 200 status in the chrome extension(app)

I have a project for a website and chrome app.
Following is a part of my code.
const payload = {
item1: 'item1',
item2: 'item2'
};
const url = 'https://api.example.com/api/login/login-callback?uid=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&exp=1673882023';
const authRequest = await axios.post(url, payload);
I've built it for chrome extension, it works well.
And then I've deployed it to my localhost, it returns 504 error status. On the live site, it is same too.
I tried to solve it in several ways, but didn't find the key.
I'd like to hear experts' opinion.

OpenAI API giving error: 429 Too Many Requests

I am trying to make a request to the openai API with the following code in express nodeJS:
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
organization: "org-Fn2EqsTpiUCTKb8m61wr6H8m",
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});
const openai = new OpenAIApi(configuration);
async function callApi() {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
max_tokens: 3000,
temperature: 0,
});
console.log(response.data.choices[0].text);
}
callApi();
The problem is that I keep getting error 429 Too many requests.
Here some more information:
The API key is correct.
When I go to my openai account > view API KEY: it shows that the key was never used so I have never been able to make a call. So how is it possibile that I'm getting error Too many requests?
I have already tried to implement exponential backoff in the function, but it didn't work.
The answer is in the error that you have received.
The error 429 Too Many Requests means that you have exceeded your free $18 in API credits. You can pay for more on the official website.
It's not possible that your key is correct but is not being used when you try to make a request. Double check that you are using the correct key in your code.

ERROR - TypeError: Type error only on Safari after made GET request to the api server inside angular 5 app

So I am making the web app on top of angular 5.
The problem is when I try to call the api endpoint from the server.
When I get an error response (400+), it seems like on Safari it always throws and breaks the app.
ERROR - TypeError: Type error
ERROR CONTEXT – DebugContext_ {view: Object, nodeIndex: 0, nodeDef: Object, …}
But on Chrome it can handle the error correctly like this.
GET https://api.xxxx.com/projectname/v1.0/validation/access-token 400 (Bad Request)
This is my source code
const baseUrl = environment.apiUrl;
const fullUrl = baseUrl + '/productname/v1.0/validation/access-token';
const headers = new HttpHeaders({
'X-Access-Token': access_token
});
this.http.get(fullUrl, {
headers: headers
}).subscribe((res: any) => {
console.log(res, 'http res');
},
(error: any) => {
console.log(error, 'http err');
});
Anyone has an idea how to fix this?
After a lots of debugging, I figured out the issue that was causing for me. In every request, I was sending the name of the mobile device and for my case it was, Shashank's iPhone.
Calling setRequestHeader with single quote in the header was failing and hence all the HTTP request broke.
I had a Flutter App using an Inapp_Webview that points to an Angular 1.X web application and was also receiving a TypeError for all XHR requests after changing my iOS device name to include an apostrophe.
(*wanted to leave a comment, but didn't have the rep yet)

Property `message` in error response body cannot be accessed | Hyperledger Fabric

Description
Using node I make a typical API POST request for which I have a .catch block with response variable say err. On error, the response body is returned as such (as seen from the Hyperledger Composer REST app)
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)",
"stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)\n at _initializeChannel.then.then.then.then.catch (/home/ubuntu/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:839:34)"
}
}
My Issue
I am simply trying to fetch the message property from the above response and send it to the UI. But weirdly err.message does not give me the value I see inside message but returns the entire response body(same with err.stack).
So basically -- err, err.message and err.stack returns the same output
How do I end up fetching only the value inside a property say message ?
PS:
err.statusCode does return the correct value ie. "500".
err.name returns "StatusCodeError"(not "Error" that I see in the response)
OK, so while not really a Hyperledger Composer question - you could try is it response.getBody() ? This is just an example, not a code snippet to use
var finalHost = "yoururl";
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod("get");
r.setEndpoint(finalHost);
//r.setQueryParameter("locatenow", "true");
r.setBasicAuth(username,password);
var response = r.execute();
var responseBody = response.getBody();
// If response is in json format, directly you can send to client.
// If not then convert it.
return responseBody;
// On client side
var newoptions = JSON.parse(jsonstring);
// returned resp.
You might consider something like Restify for error handling on UI side ?
See README at bottom here https://github.com/restify/errors/blob/master/README.md ->
https://www.npmjs.com/package/restify-errors - see this S/O here

Speech to text bing speech API Azure

When I trying to execute the code below, I get the following error:
(node:3784) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Voice recognition failed miserably: socket hang up
var fs = require('fs');
var bing = require('bingspeech-api-client');
var audioStream = fs.createReadStream('d:\\node.wav');
var subscriptionKey = 'xxxxxxxxxxxxxxxxx';
var client = new bing.BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream)
.then(response => console.log(response.results[0].name));
Please help me.
I tried with your code snippet and the example audio file in the repository at https://github.com/palmerabollo/bingspeech-api-client/tree/master/examples. It works fine on my side.
Dived into the source code, I found the error message is thrown by
throw new Error(`Voice recognition failed miserably: ${err.message}`);
at https://github.com/palmerabollo/bingspeech-api-client/blob/master/src/client.ts#L129
Usually it's an Internet issue, please double check your internet work, or you can try to ping url https://api.cognitive.microsoft.com/sts/v1.0/issueToken to check whether you have a problem connect to the API.
Came across the issue while playing with the service and it was due to the timeout settings hardcoded in bingspeech-api-client in Line 110:
open_timeout: 5000,
Full code here.
You might want to try to set higher values based on your internet connection.
if you are behind a proxy server, try setting the proxy in the node_modules\bingspeech-api-client\lib\client.js file using
https-proxy-agent
in option of all the http request, include issue token.
The below code works for me
const { BingSpeechClient, VoiceRecognitionResponse } = require('bingspeech-api-client');
const fs = require('fs');
let audioStream = fs.createReadStream("audiowav.wav");
// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
let client = new BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream).then(function(response)
{
console.log("response is ",response);
console.log("-------------------------------------------------");
console.log("response is ",response.results[0]);
}).catch(function(error)
{
console.log("error occured is ",error);
});
I think you need to import both BingSpeechClient, VoiceRecognitionResponse from bingspeech-api-client.
Here is the reference bingspeech-api-client

Resources