Not able to use 'requests' module in plugin


#1

I was following this tutorial: https://github.com/blog/2231-building-your-first-atom-plugin
After installing the requests module and following the rest I got this error.

This is my first time experience with plugin developement.
So I am not able to figure out how to fix this.

Can someone please help me ?

Here is the snapshot of the same. Including the stack trace


#2

Hello.

Is your aim to…?
(a) Get THAT specific tutorial up and running
-or-
(b) Get to learn how to create a package / add-on / extension in Atom

If your aim is to learn more about the ins-and-outs, perhaps start with
http://flight-manual.atom.io/

From this Flight Manual is also a ‘tutorial’:
http://flight-manual.atom.io/hacking-atom/sections/package-word-count/

Your thoughts?

Regards.
- Dan Padric


#3

What does my-package.js look like? The error is being thrown from there.


#4

Hello danPadric,

Thanks for answering.
The focus is definitely on learning, will read the manual.

Any luck in solving this problem though?
May be alternative library or something?


#5

Hey , Here is the code:

'use babel';
import { CompositeDisposable } from 'atom';
import request from 'request'
export default {
  subscriptions: null,
  activate(state) {
    this.subscriptions = new CompositeDisposable();
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'my-package:fecs': () => this.fecs()
    }));
  },
  deactivate() {
    this.subscriptions.dispose();
  },
  fecs() {
    let editor
    if (editor = atom.workspace.getActiveTextEditor()) {
      let selection = editor.getSelectedText()
      this.download(selection)
    }
  download(url) {
    request(url, (error, response, body) => {
    if (!error && response.statusCode == 200) {
        console.log(body)
      }
    })
  }

};

fecs() is the main function which uses download().


#6

…sorry I am just a visitor - I don’t work here. :wink:

let editor

Not knowing enough to be helpful - but isn’t an assignment missing there?


#7

No that is not the problem.( I am sure about that :smile: )


#8

I do believe you’re missing a }, to close the fecs function.


#9

Hey, Guys. I am so terribly sorry.

Yes,that was that.

My bad really. :confounded:


#10

It happens to everyone.


#11

If you don’t know what linters are, they essentially check over your code to make sure everything is :100:. That can mean anything from making sure your code will compile to checking for best practices or enforcing a specific style guide. I would recommend choosing a linter that suits you (check out https://eslint.org/ as a place to start) so that it’s harder for these things to happen in the future :slightly_smiling_face:. Atom then has the corresponding linter and linter-eslint packages that you can install.


#12

…just a thought ->
If one is just starting with experimenting with Atom,
one might not even know about what linters are for.


#13

Yes, I never heard of linters before. Thanks for sharing.Will definitely check out :slight_smile:


#14

I’m learning Python, which has a community that prides itself in modeling after the language creator’s rather particular opinions on how programming should be done, and I’ve set the linter to enforce the official style guide of the language, and conforming to that style (along with thinking critically about how I want to write and why people are saying to do this or that) has really improved my code.