Pipelet validate publication_date.py

Hi, when I learn customize Pipelet, I got errors called
configparser.NoSectionError: No section: ‘requests’
I’ve installed Requests lib but the error just showed.
Please help me solve this error

2 Likes

Welcome @vyntb!

Thank you for joining us here at the Forum :dizzy:

1 Like

Hi @vyntb thanks for raising this question. Pipelets are limited in what dependencies you can use. You can not import any external libraries except squirro.sdk . If you do need access to external libraries, you need to use the require() decorator.

Check out the documentation on how to properly use dependencies when writing a custom pipelet, in particular, the requests dependency.

For your convenience, I have also included this below:

The @require decorator takes a name of a dependency. That dependency is then available within the pipelet class.

from squirro.sdk import PipeletV1, require

@require('requests')
class SentimentPipelet(PipeletV1):
    def consume(self, item):
        text_content = ' '.join([item.get('title', ''),
                                item.get('body', '')])
        res = self.requests.post('http://example.com/detect',
                                data={'text': text_content},
                                headers={'Accept': 'application/json'})
        sentiment = res.json()['sentiment']
        item.setdefault('keywords', {})['sentiment'] = [sentiment]
        return item
1 Like