0

so I am trying to use the requests module to make an auto-updater for my program. I want to take the text from a Pastebin file and use that as my code. This is what I've done so far.

import requests

coderaw = requests.get('https://pastebin.com/raw/s3d1kWgu')

code = coderaw.text

So I want the "code" variable to be my source code. Does anybody know a module or an operator that lets me do this?

Thanks.

2
  • 2
    Are you aware of the implication of doing that? Commented Feb 22, 2021 at 1:59
  • This is a very bad idea; at least validate the code you download using a cryptographic signature or something. What you are currently trying to do would basically give full control of your computer (or your users' computers, if your program is used by anyone else) to whoever either gets your pastebin password or otherwise acquires the ability to edit what's at that pastebin link. Commented Feb 22, 2021 at 2:03

2 Answers 2

1

You can use exec to execute the code in coderaw, for example:

my_code = 'print ("Hello World!")'
exec(my_code)

Using your code:

import requests
coderaw = requests.get('https://pastebin.com/raw/s3d1kWgu')
code = coderaw.text
exec(code)
Sign up to request clarification or add additional context in comments.

Comments

0

If you are willing to take the risk then you can just exec it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.