This function grabs a python script from a paste on pastebin with the title py_0001, when the execution reaches the try: except: it throws an error
SyntaxError: unexpected character after line continuation character
If you copy value of script_ and declare it as a string variable it executes without any errors
The function works fine until it reaches the error handling part
def get_script():
''' grabs python script from pastebin '''
reg_ = r'[a-zA-Z0-9]*\">py_0001'
resp = requests.get(url='https://pastebin.com/u/'+usr_name)
path = re.findall(reg_ , str(resp.content) , re.MULTILINE)
url2 = "https://pastebin.com/raw/"+ str(path[0]).replace('">py_0001' , '')
resp2 = requests.get(url2)
script_ = str(resp2.content)[2:-1]
print (script_)
try:
exec(script_)
except:
print ("3rr0r")
This is the output of the paste on pastebin
import os\r\nimport time \r\nimport random \r\n \r\ndef fun_9991():\r\n ## a simple code example to test \r\n for i in range (0 , 10 ):\r\n print ( " loop count {} , random number is {} , time is {} ".format(i , random.randrange(10) , int(time.time()/1000)))\r\n print ("loop reached the end")\r\n \r\n \r\nif __name__ == "__main__":\r\n fun_9991()\r\n\r\n\r\n
exec? is it the complete python script?str()on a bytes object. Use.decodeinstead.