bonzanini / Book-SocialMediaMiningPython

Companion code for the book "Mastering Social Media Mining with Python"
546 stars 265 forks source link

Always get Twitter Environment Variable Not set #7

Closed AdherenceDigital closed 7 years ago

AdherenceDigital commented 7 years ago

Hi, I feel a bit silly asking really but here is the issue. I have the code as documented for the twitter_client.py and the home_timeline.py (copied and pasted the code to eradicate any errors caused by my fingers).

I have these two files in the same folder as advised. I am on a Mac and have my /etc/paths with:

export TWITTER_CONSUMER_KEY="my_key_here" and so on for all 4 variables. I have also tried this without 'export' at the front.

When I run the twitter_client.py file by itself, I get no errors, but when I then run hometimeline.py it throws the error "TWITTER* environment variables not set".

Printing out os.environ shows the keys + secrets as expected. I'm going round in circles trying to nail down where the issue lies so I would be very grateful for any help!

Thanks, Peter

bonzanini commented 7 years ago

On macOS you can put the four export commands in the file ~/.bash_profile

The instructions on this file are executed when you open a new shell, so you can use them to personalise the environment.

The reason you don't see any error when running the twitter_client.py file is that it contains only function definitions, so nothing really happens besides defining these functions.

The file /etc/paths serves another purpose (setting the starting point for the $PATH environment variable for all users)

hth

AdherenceDigital commented 7 years ago

Thank you so much! It now works gloriously! I knew it would be a small thing but couldn't see the wood for the trees.