0

I tried to make a Twitter bot from https://github.com/joaquinlpereyra/twitterImgBot

The installations went well and successfully but the problem came when I tried to execute it.

Below is the code for my config in the config.py. Keys and Tokens removed with the API key replaced with random numbers because that's the problem I'm trying to address.

import os
import configparser
import tweepy

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
# read configs from file
config = configparser.ConfigParser()
config.read(dname + '/settings')
twitter_config = config['Twitter']
api_key = twitter_config['2931928391273123']
secret_key = twitter_config['REMOVED']
token = twitter_config['REMOVED']
secret_token = twitter_config['REMOVED']

The error I'm getting when executing it in cmd is:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd C:\Documents and Settings\Administrat
or\Desktop\twitterImgBot-master

C:\Documents and Settings\Administrator\Desktop\twitterImgBot-    master>python twitterbot.py
Traceback (most recent call last):
  File "twitterbot.py", line 3, in <module>
 from settings import config
File "C:\Documents and Settings\Administrator\Desktop\twitterImgBot-master\settings\config.py", line 13, in <module>
api_key = twitter_config['2931928391273123']
File "C:\Python34\lib\configparser.py", line 1203, in __getitem__
raise KeyError(key)
KeyError: '2931928391273123'

C:\Documents and Settings\Administrator\Desktop\twitterImgBot-master>

I looked up all the questions here that has something to do with KeyError but none of them have something to do with the Twitter's API key

Again, the API key which is 2931928391273123 is just a random number to substitute the original one for obvious reasons. I did double check it to make sure I had the correct keys/tokens before resorting to here.

This is also a first for me, so I'm hoping someone can lend me a helping hand! I would have posted the 2 screenshots of the Python file and the cmd but I'm only limited to one link. Thanks in advance!

linusg
  • 6,289
  • 4
  • 28
  • 78
joey wong
  • 1
  • 2
  • Can you print the config dictionary to check what keys do you have? – lapinkoira Apr 05 '16 at 11:30
  • @lapinkoira Thanks for the quick reply, but how do I check that? It doesn't make sense to me that API keys has something to do with the config dictionary. If it's any help, here're the two screenshots that I never got my chance to post in my question. http://imgur.com/a/hNPVB – joey wong Apr 05 '16 at 11:39
  • What I mean is, you are loading a configuration file from /settings and that configuration file is parsed into a dictionary. IF you receive a KeyError it doesnt have anything to do with Twitter, it just mean the setting value doesnt appear in the file, can I see an example of the setting file? – lapinkoira Apr 05 '16 at 11:46

0 Answers0