i have an annoying problem.
I have such a code:
const configuration = new Configuration({
apiKey: "OpenAI key"
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImage({
prompt: "a white siamese cat",
n: 1,
size: "1024x1024",
});
data.result = response['data'][0]['url']
console.log(data.result)
when i type the command i get this error:
Error: Request failed with status code 400
at createError (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\adapters\http.js:322:11)
at IncomingMessage.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1342:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Is anyone able to help me? I've tried everything and it still doesn't work...
Related
So I am trying to get some data from the food-data-central API. In my program I console log the data, but I don't get any results on the console.
The only thing I get is an error about Fetch Error
import fetch from "node-fetch"
const params = {
api_key: <apiKey>,
query: 'chicken breast raw',
dataType: ["Survey (FNDDS)"],
pagesize: 5,
}
const api_url = `https://api.nal.usda.gov/fdc/v1/foods/search?api_key=${encodeURIComponent(params.api_key)}&query=${encodeURIComponent(params.query)}&dataType=${encodeURIComponent(params.dataType)}&pageSize=${encodeURIComponent(params.pagesize)}`
function getData(){
return fetch(api_url).then(response => response.json())
}
getData().then(data => {
const foods = data.foods[0];
console.log("Protein: ");
console.log(foods.foodNutrients[0].value);
console.log("Fats: ");
console.log(foods.foodNutrients[1].value);
console.log("Carbs: ");
console.log(foods.foodNutrients[2].value);
});
The output that I get:
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://api.nal.usda.gov/fdc/v1/foods/search?api_key=3Bi6rNu3MiTYMaPwMf2u5vs1xAtdKS0n5HoFpgy9&query=chicken%20breast%20raw&dataType=Survey%20(FNDDS)&pageSize=5 failed, reason: connect ETIMEDOUT 2600:1f12:18a:7d00:217:68d:2c2:3718:443
at ClientRequest.<anonymous> (/home/dflorian251/Desktop/node_modules/node-fetch/lib/index.js:1505:11)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketErrorListener (node:_http_client:481:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
Is something wrong with the node-fetch module ?
Hello i want to create a bot who will automatically send a message to the men who follow you
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var stream = T.stream('user');
stream.on('follow', followedMessage);
function followedMessage(eventMsg) {
console.log('+1 follow');
var fs = require('fs');
var json = JSON.parse(eventMsg);
fs.writeFile("tweet.json", json)
}
but when i start the app i got this error
throw er; // Unhandled 'error' event
^
Error: Bad Twitter streaming request: 404
at Object.exports.makeTwitError (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\helpers.js:74:13)
at Request.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:96:29)
at Request.emit (events.js:327:22)
at IncomingMessage.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\request\request.js:1076:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on StreamingAPIConnection instance at:
at Request.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:99:14)
at Request.emit (events.js:327:22)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: null,
allErrors: [],
twitterReply: '',
statusCode: 404
}
someone can help me ?
Replace:
var stream = T.stream('user');
With
var stream = T.stream('statuses/filter', { track: '#<your_twitter_username>' });
Thanks to Asaolu Elijah Response on github issue
i dont think that T.stream('user'); is still working now, i have a mission now to built a bot for a client and i had the same problem,
Try to use T.stream('statuses/filter'), or T.stream('sample')
I've installed prosody on an ubuntu AWS server. I have tried using Adium client and swift, but I get the same error indicated in the title. I've tried using node-xmpp-client to create a client but same error.
Node-XMPP client code:
const Client = require('node-xmpp-client');
const options = {
jid: 'test#ec2-18-222-249-134.us-east-2.compute.amazonaws.com',
password: 'password',
host: 'ec2-18-222-249-134.us-east-2.compute.amazonaws.com'
}
const client = new Client(options);
client.once('online', connectionDetails =>{
console.log('We are connected');
console.log(connectionDetails);
});
Error Message:
Error: No stream features to proceed with
at Connection.onStanza (/Users/my-name/BeginXMPP/node_modules/node-xmpp-core/lib/Connection.js:363:17)
at StreamParser.<anonymous> (/Users/my-name/BeginXMPP/node_modules/node-xmpp-
core/lib/Connection.js:231:10)
at StreamParser.emit (events.js:198:13)
at SaxLtx.<anonymous> (/Users/my-name/BeginXMPP/node_modules/#xmpp/streamparser/index.js:69:14)
at SaxLtx.emit (events.js:198:13)
at SaxLtx._handleTagOpening (/Users/my-name/BeginXMPP/node_modules/ltx/lib/parsers/ltx.js:40:12)
at SaxLtx.write (/Users/my-name/BeginXMPP/node_modules/ltx/lib/parsers/ltx.js:159:18)
at StreamParser.write (/Users/my-name/BeginXMPP/node_modules/#xmpp/streamparser/index.js:134:17)
at Connection.onData (/Users/my-name/BeginXMPP/node_modules/node-xmpp-core/lib/Connection.js:310:17)
at Socket.emit (events.js:203:15)
Emitted 'error' event at:
at Client.<anonymous> (/Users/my-name/BeginXMPP/node_modules/node-xmpp-client/lib/Client.js:158:23)
at Connection.emit (events.js:203:15)
I'm using firebase realtime database and cloud functions. The goal is on a create event in realtime database to send a message to Discord webhook.
I'm getting a 400 status error and can't work out how to get around it.
Here is my code:
const WEBHOOK_URL = 'MY DISCORD WEBHOOK URL';
exports.webhook = functions.database.ref('{sessionId}').onCreate(async (snap) => {
const sessionData = snap.val();
const response = await request({
uri: WEBHOOK_URL,
method: 'POST',
json: true,
body: sessionData.dateCreated,
resolveWithFullResponse: true,
});
if (response.statusCode >= 400) {
throw new Error(`HTTP Error: ${response.statusCode}`);
}
console.log('SUCCESS! Posted', snap.ref);
And the error message:
Error ->
StatusCodeError: 400 - {"_misc":["Only dictionaries may be used in a DictType"]}
at new StatusCodeError (/srv/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/srv/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/srv/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/srv/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/srv/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
My problem i that I get an error telling me I can't make post request. I use the insertDocuments function to insert messages into a database. I am attempting to make a promise oriented version of the 'mongolab-data-api' node.js module. I apologize if my question is confusing
//This is a function in a class that handles all mlab related things
var rp = require('request-promise')
var insertDocuments = options => {
if (!options.database || !options.collectionName || !options.documents) throw new Error('Database name, Collection Name, and Document(s) are required')
var opt = {
uri: `https://api.mongolab.com/api/1/databases/${options.database}/collections`,
qs: {
apiKey: this.apiKey
},
method: 'POST',
body: {
documents: options.documents
},
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
return rp(opt)
}
var options = {
database: 'lexybase',
collectionName: 'evy-history',
documents: msg
}
insertDocuments(options)
I get this error:
Unhandled rejection StatusCodeError: 405 - {"message":"POST not allowed."}
at new StatusCodeError (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request-promise-core/1.1.1/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request-promise-core/1.1.1/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request-promise-core/1.1.1/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request/2.88.0/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request/2.88.0/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/rbd/pnpm-volume/b50cbf1c-9de1-48a8-8200-48301efdd80c/node_modules/.registry.npmjs.org/request/2.88.0/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)
Edit: As it turns out, the problem was that collectionName need3d to be specified and it shoul have been
body: options.documents
instead of
body: {
documents:options.documents
}
You are missing the collection name in uri:
uri: https://api.mongolab.com/api/1/databases/${options.database}/collections
should be:
uri: https://api.mongolab.com/api/1/databases/${options.database}/collections/{collectionName}
just change the collectionName
405 is returned from mongolab API