0

I have done everything correctly and putted everything key correctly. So why it is showing the error.

`import tweepy
import openai

# replace the placeholders with your own keys and tokens
consumer_key = 'my-key'
consumer_secret = 'my-secret'
access_token = 'my-token'
access_token_secret = 'my-toke n'

openai.api_key = "openai-key"

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="give a unique and short thrilling horror story which scares the humans for a tweet with no hashtags\n",
  temperature=1,
  max_tokens=256,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)
text=response.choices[0].text + " #horror #scary #creepy #creepypasta"

def tweet_now():
    msg = text
    try:
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth)
        try:
            api.verify_credentials()
            print("Authentication OK")
        except:
            print("Error during authentication")
        # Create a client instance
        client = tweepy.Client(auth)

        tweet=client.create_tweet(text=msg,)
        print(msg)

        print("Tweeted")
    
    except Exception as e:
        print(e)
tweet_now()
print(text+'\n\nDone!')`

But is giving this error

Authentication OK
Consumer key must be string or bytes, not NoneType

She woke up in a cold sweat,realizing it wasn't a dream. The noises coming from outside were growing louder and closer. She knew what it was coming for her and she had to run. But, too late. The door burst open and the creature was here. #horror #scary #creepy #creepypasta

Done!

I was expecting that it tweets a horror story.

InSync
  • 4,851
  • 4
  • 8
  • 30
  • Everything seems correct for me, I don't know if I miss something but I only think one possible reason for it, you changed your consumer_key, secret, bla bla variables in here with default texts, but in your code, if you use os.environ, you may be typed environment variable name incorrectly. Check os.environ.get("key") with print to see if they return correctly. But the problem is Authentication return OK, that doesn't make sense at all. You can try to check all variables if they are NoneType or not to see where is the issue. – Hamit Devecioğlu Apr 24 '23 at 23:58
  • Please simplify your code by removing the OpenAI bit; it’s just noise as it has nothing to do with the error. Also, please specify which version of Python and Tweepy you are using. – bfontaine Apr 25 '23 at 08:24
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Apr 25 '23 at 08:24

0 Answers0