skip to Main Content

I am trying to write my first “helloworld” program to post on Twitter.
The program works fine with print("helloworld").
It also works with import tweepy.
But as soon as I try to assign my IDs, I get errors that it doesn’t recognize the API calls. (see attached screenshot)
Maybe its obvious, but I am a beginner Python programmer, and I’m basically copying what I saw in a YouTube video.

code+terminal screenshot

2

Answers


  1. Chosen as BEST ANSWER

    I accidentally typed “python helloworld.py” instead of “python3”and it magically worked! So now I just run it that way.


  2. You should be able to fix this issue by replacing the import with

    from tweepy.auth import OAuthHandler
    

    and then replace your auth= line with

    auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    

    Now as to why this is occuring – it could be dependant on what’s being imported. If you have another tweepy.py file for example, it could be getting picked up as the file to import from, which of course, is likely wrong. Using the from import resolves this. You can find out which file was being used by adding (still using the code from the version in the image you posted)

    print(tweepy.__file__)
    

    This’ll give you an idea whether the correct file was being imported or not.

    Hope that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search