I just deploy a python app in a free Heroku server. This python app provides a telegram bot to me. I want the bot to modify the userconfig.json
which is in the same directory with main.py
. When I test my bot in my local machine, it works well, the userconfig.json
can be modified, but when app deploys on Heroku, it can't modify the file. After sending the modify
order, there is no change on my userconfig.json
. How can I solve this problem?
Below is the member method which modifies the json file
def modify_token(self, new_token):
self.tokenArray[0] = new_token
token_update = [{'token': self.tokenArray[0]}]
try:
with open("./userconfig.json", 'w') as config:
json.dump(token_update, config)
except Exception as e:
return False
return True
And I use these codes to ask telegram bot to modify the file
def modify(update: Update, context: CallbackContext):
# print(context)
print(context.args)
try:
user_cake.modify_token(context.args[0])
except Exception as e:
err_res = str(e)
context.bot.send_message(chat_id=update.effective_chat.id, text="An error occurred:" + err_res)
else:
context.bot.send_message(chat_id=update.effective_chat.id, text="Your new token is: " + user_cake.tokenArray[0])