-2

So, im trying to make a script that takes code from a pastebin post and runs it. But, for some reason it doesnt run the code. I dont know why. Could someone explain why this wont work so i can fix the issue?

I tried: (dont mind the imports im gonna use those for later)

import os 
from json import loads, dumps
from base64 import b64decode
from urllib.request import Request, urlopen
from subprocess import Popen, PIPE

def get_code():
  test = 'None'
  try:
    test = urlopen(Request('https://pastebin.com/raw/4dnZntN3')).read().decode()
  except:
    pass
  return test

test = get_code()

def main():
  test

main()

The output is empty, and no errors.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
pamp
  • 1
  • 3
    You never print anything. It probably does something, but you have no way of seeing it – DavidW Nov 21 '22 at 13:16
  • 1
    `def main(): test` definitely does not do what you think it does. `test` is just a `str` object that happens to be [probably] a python code. Still. it's just a string. It's same if it was `def main(): 'print("3"+"2")'` – buran Nov 21 '22 at 13:18
  • The pastebin post contains the code "print("3"+"2")". – pamp Nov 21 '22 at 13:18
  • The content of the pastebin post is irrelevant. If you want to print output to stdout, you have to call functions like `print()` in your code. – kotatsuyaki Nov 21 '22 at 13:19
  • A Stack Overflow's title should be _specific to that individual question_. Don't refer to "this"; spend the title space to describe what "this" is. – Charles Duffy Nov 21 '22 at 13:19
  • 2
    Downloading and running some arbitrary code from the internet seems like a security risk and generally just a bad idea – Iain Shelvington Nov 21 '22 at 13:19
  • @buran Any way i can solve this? As i said, im fairly new to python. – pamp Nov 21 '22 at 13:20

2 Answers2

0

In your main function instead of just printing test use exec(test)

def main():
    exec(test)
vineet singh
  • 173
  • 2
  • 12
-2

you are printing nothing and 'return test' wont be ran because it is outside of the try block