Python "Chatbot" (NO API KEYS NEEDED!)

Today I’m gonna teach you how to use a Buit-In Python Chatbot:

while True:
  try: print(eval(input(">>> ")))
  except:
    print("Unavailable command")

Now you have a working chatbot*!

*The chatbot may not be as useful as ChatGPT

2 Likes

How to crash a Python Chatbot 101:

>>> exit()

And done!


I know this is a joke, but please don’t use eval() in your actual projects, its a huge security flaw. If the user knew how, I think they could override a variable or something

Screenshot 2023-06-03 8.41.51 AM

Even if you have handling for exit, or any other exception, you could also just call this:

exec(type((lambda: 0).__code__)(0, 0, 0, 0, 0, 0, b'\x053', (), (), (), '', '', 0, b''))

From Stack Overflow.

2 Likes

Sorry, what does this do?

It causes python to crash completely, even if you have a blank try-except block in place (Which is bad practice regardless), and is one reason not to eval inputs.

what do you mean? __

Basically:

  1. eval() is bad, do not use it if avoidable.
  2. If you do use eval, then someone can enter code into it and overwrite/add to your project.

Could someone explain what eval( ) does?
(I’ve never used it before)

it’s basically does some python code; it can execute python code or can tell information about python code.

1 Like

It basically evaluates the code you put into it. Say you put 5+2 in, it’ll return 7. Or say you did "a"+"bc", then it’d return "abc". It’s dangerous, because you can also directly execute python code from eval by just calling exec.

1 Like