Apify Discord Mirror

Updated 6 months ago

RequestQueue Issue

At a glance

The community member has provided some code that they are using, which is causing an error. A comment suggests that instead of adding URLs as strings, the community member should create Request objects and add those to the queue. This may help resolve the issue the community member is facing.

Useful resources
I have used this code.
which is provided onsite for example.
Plain Text
// Import the JavaScript SDK into your project
import { Actor } from 'apify';

await Actor.init();
// ...

const queue = await Actor.openRequestQueue();

// Enqueue requests
await queue.addRequests([{ url: 'http://example.com/aaa' }]);
await queue.addRequests(['http://example.com/foo', 'http://example.com/bar'], {
    forefront: true,
});

// Get the next request from queue
const request1 = await queue.fetchNextRequest();
const request2 = await queue.fetchNextRequest();

// Get a specific request
const specificRequest = await queue.getRequest('shi6Nh3bfs3');

// Reclaim a failed request back to the queue
// and process it again
await queue.reclaimRequest(request2);

// Remove a queue
await queue.drop();

// ...
await Actor.exit();


I am getting this error.
Attachment
image.png
O
1 comment
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/in_operator_no_object

maybe try this:
Plain Text
// instead of:
await queue.addRequests(['http://example.com/foo', 'http://example.com/bar'], {
    forefront: true,
});

// try to add Request object (https://crawlee.dev/api/core/class/Request):

await queue.addRequests([
    {
        url: 'http://example.com/foo',
    },
    {
        url: 'http://example.com/bar'
    }
], {
    forefront: true,
});
Add a reply
Sign up and join the conversation on Discord