Problems using Graphapi in Python - "there is no Graphapi attribute in the Facebook Module"?

Asked

Viewed 33 times

0

Hello, so, as the title suggests, I’m trying to use graphAPI facebook but without success, my goal is to do data mining for data science, but I’m not having much success, I’m following the documentation and everything, only I keep finding this error:

`AttributeError: partially initialized module 'facebook' has no attribute 'GraphAPI' (most likely due to a circular import)`

The code in question is this:

facebook py.

   import os
   import dotenv
   import facebook
   import urllib3
   
   dotenv.load_dotenv()
   
   token = os.environ['USER_ACCESS_TOKEN']
   
   graph = facebook.GraphAPI(access_token=token, version=8.0)
   events = graph.request('/search?q=Teste&type=event&limit=10000')

I had my first contact with Graphapi today, only I got there and I can’t find anything on Google, everything points to the same path, I don’t know if it’s something I did wrong in the project as a whole, or I stopped installing some requirement.

And lastly, the access keys are correct(at least as far as I know).

Thanks in advance!

  • 1

    Does your file name happen to be facebook.py? If it is, renaming it should solve the problem, as in this case the Python interpreter would be looking for Graphapi inside your file. Furthermore, try to describe what is the "same path" that was pointed out in your research and you tried as a solution. Knowing what you have tried facilitates in solving the problem.

  • That was his name, thank you! As for the "same way" part I wanted to say how the Graphapi part was, but anyway, thank you so much for the help!

1 answer

0


The problem is that your script has the name of `facebook.py' and it happens by the way the module import works in Python.

When we write import foo or from foo import bar, Python will search for the module foo in the following places:

  1. Embedded module.
  2. The directory in which the script is running.
  3. PYTHONPATH, similar to variable $PATH, contains a list of directories.
  4. Default directories (depend on installation)

In the case of the topic question, name the script as facebook.py makes Python look for GraphAPI in the script facebook.py. Renaming this file to a different name will cause Pyhton to correctly import the module facebook, which will be found in any of the directories listed in PYTHONPATH.

  • That’s right! It was lack of attention on my part. Now it’s all working right, Thanks for the help!

Browser other questions tagged

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