Get method error in Python Requests library

Asked

Viewed 370 times

0

I’m trying to learn how to use the library Requests in python, but there is an error that I do not know how to solve, in several tutorials creates the variable r = requests.get('https://api.github.com/events') but my Vscode shows an error => Module 'requests' has in the get 'Member. Get is not a re methodinserir a descrição da imagem aquiquests?

  • Which version of python is using friend? What if you try to run that same command from the command line, other than VSCODE, from the error?

  • to using python 3.7.4 and in Idle it runs normally, I’m just confused because Vscode does not accept the method.

  • How strange, I’m using the version Python 3.6.8 and VSCODE 1.38.0 and I can’t reproduce this error you showed, in mine is recognized normally. Using some extension to python in vscode?

  • Using the microsoft python extension, I will try to update Vscode to see if I can solve this.

  • 1

    It’s not a problem in VS Code, but in your file. You named the file as requests.py, so when does import requests you are importing the file itself on itself instead of importing the library. As your file does not have a get defined gives error. Never name your files with names of Python modules.

  • Anderson, I have a file called scan_dns_directories.py and it uses requests, and it presents the same error, I believe that is not it, despite being a bad programming practice, but I will change the name of the file kkk.

  • If the file is in the same directory has exactly the same problem, importing your requests.py file instead of the library. In module name resolution Python will always prioritize local modules before searching for global ones.

Show 2 more comments

1 answer

1

The problem is that your file is named as requests py.. The error is being generated because you are not importing the library requests but its module that does not have the function get. This error will be presented not only for this module but for others who will import your requests py..

Rename it to another name and test again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.