简体   繁体   English

使用 python 应用程序在 heroku 上创建和读取 .txt 文件

[英]create and read a .txt File on heroku with python app

i created Line-bot app using heroku as host, which can create, read, and append into a txt_files on heroku by sending a command from Line account,我使用 heroku 作为主机创建了 Line-bot 应用程序,它可以通过从 Line 帐户发送命令来创建、读取和附加到 heroku 上的 txt_files 中,

so i tried to sent message to my Line-bot with command like this:所以我试图用这样的命令向我的 Line-bot 发送消息:

username = "user_name"
password = "pass_word"

i sent that text to my Line-bot and it saves my username and password into a txt_file(of course it check if there was no txt_file for save those data it will create txt_file automatically) on heroku, and by another command which can read the text which my Line-bot saved last time, my Line-bot sent me message and it shows:我将该文本发送到我的 Line-bot 并将我的用户名和密码保存到 heroku 上的 txt_file 中(当然它会检查是否没有 txt_file 来保存这些数据,它将自动创建 txt_file),并通过另一个可以读取我的 Line-bot 上次保存的文本,我的 Line-bot 给我发送了消息,它显示:

username is user_name
password is pass_word

however after a few hours when i need my username and password/read back my data, by sending the same command, the data is gone and becomes like this但是几个小时后,当我需要我的用户名和密码/读回我的数据时,通过发送相同的命令,数据消失了,变成了这样

username is //empty 
password is //empty

what should i do for this problem?我该怎么办这个问题?

thank you...谢谢...

Are you using a free-level heroku account?您使用的是免费级别的 heroku 帐户吗? If so, heroku does not allow permanent (long-term) file storage.如果是这样,heroku 不允许永久(长期)文件存储。 As long as the dyno is shut down, any changes will be reverted.只要 dyno 关闭,任何更改都会恢复。

An alternative is to use an external server as a database, but those may suffer from slower connection.另一种方法是使用外部服务器作为数据库,但这些服务器可能会受到连接速度较慢的影响。

This article tells you more about heroku. 这篇文章会告诉你更多关于 heroku 的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM