Python Read/write 服务器
Python Read/write server
您好,我想知道是否有一台服务器可以让我像使用 .txt 文件一样对其进行读写。我还希望能够从任何可以访问互联网的计算机访问它。我只是一个 child,我真的没钱买一个昂贵的,所以 free/cheap 一个会更可取。
我想用它来创建聊天室(仅供我和我的朋友使用)或存储游戏高分的地方。所以只需要500mb。
如果可以,能告诉我怎么用吗?
谢谢
有很多方法可以做到这一点。我也曾经遇到过这样的情况,我需要一种免费的方式来安全地在线存储数据,以满足我在应用程序中的小需求。
我研究了一下,以下似乎是可能的解决方案-:
- Firebase-: There is a special python module called pyrebase 处理 firebase 的数据发送和接收,它是由 google 开发的,所以它也很安全。另一个优点是它与 android 和 ios 交叉兼容,而且由于 android 确实使用 firebase,而 firebase 最初是为 android 开发和提供数据库服务而开发的仅限 android。此 API 的实时数据库功能可轻松用于您的用例。 API 虽然有一些功能是免费的,但不是全部。如果您使用的是免费计划,则每月可以发送的请求数量有限制,但对于非官方测试的程序来说,这个限制已经绰绰有余了。
另请注意,它确实将您限制为 python,并且它拥有 API 的功能。它虽然可以帮助您处理很多与服务器相关的事情,而无需从头开始设置。
- Heroku + SocketStuff -: There also exists a service called heroku, which lets you set up your applications on cloud, so you do not need to have your own server set up for running your application, But unlike firebase it lets you customize everything, but it also means that the database has to be made by you and uploaded on heroku along with a python file that can act as a worker file and receive requests for data upload/transfer. Again, this is completely free till a limit, but I found myself comfortably being able to fit most of the programs in that limit, and having a single worker file would not cross that limit. The python file that will accept requests for data will need to use the socket图书馆这样做。这样您将拥有更 pythonic 和更深入的方式来处理您的数据,因为 python 文件是定制的,不像 firebase 内置了 APIs 用于数据交换。另请注意,此方法的结论是它确实增加了您可以使用这些服务器执行的操作的能力限制,但它也将大部分服务器文件代码留在您手中,这很好,但可能会耗时一些案例。
- PythonAnywhere -: This is a cloud application hosting service specially designed for python related applications, so it will provide you a more user friendly and understandable interface. But some python features such as asynchronous stuff, does not really work properly in all cases, and it cannot be fixed as mentioned here 在他们的论坛中。与 heroku 类似,您必须自己设置服务器端代码,它没有为您处理。它也有更严格的限制,但这取决于用例。它再次免费使用,直到达到一定的限制,您需要付费才能使用额外的功能或超过限制。请注意,它的可定制性不如 heroku,而且与 firebase 不同,它可能不会很好地支持 android,因为 android 和 python 并不常见。但对于 python 人来说,这是一个很好的起点。
我个人是从使用 Firebase 开始的。后来我发现了 Heroku,对我来说,它似乎是一个更好的选择,可用于某些项目,但并非适用于所有项目。
我真的很喜欢 python 在任何地方的界面,以及你需要设置的一切都非常清晰,但事实上它不能 运行 异步代码是我决定切换的地方。
编辑: 另外,当你提到你想存储游戏高分或聊天室的聊天记录时,我建议你使用 firebase,因为你为你和你的朋友指出了它,所以它基本上用于非官方测试目的,pyrebase 模块的文档简短易懂(请注意,它仅在 github 页面中提供)。其他两个备选方案可以用于需要更多代码自定义的其他项目。
要设置 firebase,您需要转到 firebase console first and setup a project there, then you will need to create the realtime database, and then go to project overview to get the details(refer to pyrebase docs to understand which details you will need, direct link here),您需要在 python 文件中输入该内容以设置连接。
要使用数据库服务,您还需要为其初始化一个对象,如前所述here。
我建议您直接看一下讨论数据保存和检索的 this 部分 pyrebase 文档。
您好,我想知道是否有一台服务器可以让我像使用 .txt 文件一样对其进行读写。我还希望能够从任何可以访问互联网的计算机访问它。我只是一个 child,我真的没钱买一个昂贵的,所以 free/cheap 一个会更可取。
我想用它来创建聊天室(仅供我和我的朋友使用)或存储游戏高分的地方。所以只需要500mb。
如果可以,能告诉我怎么用吗? 谢谢
有很多方法可以做到这一点。我也曾经遇到过这样的情况,我需要一种免费的方式来安全地在线存储数据,以满足我在应用程序中的小需求。
我研究了一下,以下似乎是可能的解决方案-:
- Firebase-: There is a special python module called pyrebase 处理 firebase 的数据发送和接收,它是由 google 开发的,所以它也很安全。另一个优点是它与 android 和 ios 交叉兼容,而且由于 android 确实使用 firebase,而 firebase 最初是为 android 开发和提供数据库服务而开发的仅限 android。此 API 的实时数据库功能可轻松用于您的用例。 API 虽然有一些功能是免费的,但不是全部。如果您使用的是免费计划,则每月可以发送的请求数量有限制,但对于非官方测试的程序来说,这个限制已经绰绰有余了。 另请注意,它确实将您限制为 python,并且它拥有 API 的功能。它虽然可以帮助您处理很多与服务器相关的事情,而无需从头开始设置。
- Heroku + SocketStuff -: There also exists a service called heroku, which lets you set up your applications on cloud, so you do not need to have your own server set up for running your application, But unlike firebase it lets you customize everything, but it also means that the database has to be made by you and uploaded on heroku along with a python file that can act as a worker file and receive requests for data upload/transfer. Again, this is completely free till a limit, but I found myself comfortably being able to fit most of the programs in that limit, and having a single worker file would not cross that limit. The python file that will accept requests for data will need to use the socket图书馆这样做。这样您将拥有更 pythonic 和更深入的方式来处理您的数据,因为 python 文件是定制的,不像 firebase 内置了 APIs 用于数据交换。另请注意,此方法的结论是它确实增加了您可以使用这些服务器执行的操作的能力限制,但它也将大部分服务器文件代码留在您手中,这很好,但可能会耗时一些案例。
- PythonAnywhere -: This is a cloud application hosting service specially designed for python related applications, so it will provide you a more user friendly and understandable interface. But some python features such as asynchronous stuff, does not really work properly in all cases, and it cannot be fixed as mentioned here 在他们的论坛中。与 heroku 类似,您必须自己设置服务器端代码,它没有为您处理。它也有更严格的限制,但这取决于用例。它再次免费使用,直到达到一定的限制,您需要付费才能使用额外的功能或超过限制。请注意,它的可定制性不如 heroku,而且与 firebase 不同,它可能不会很好地支持 android,因为 android 和 python 并不常见。但对于 python 人来说,这是一个很好的起点。
我个人是从使用 Firebase 开始的。后来我发现了 Heroku,对我来说,它似乎是一个更好的选择,可用于某些项目,但并非适用于所有项目。 我真的很喜欢 python 在任何地方的界面,以及你需要设置的一切都非常清晰,但事实上它不能 运行 异步代码是我决定切换的地方。
编辑: 另外,当你提到你想存储游戏高分或聊天室的聊天记录时,我建议你使用 firebase,因为你为你和你的朋友指出了它,所以它基本上用于非官方测试目的,pyrebase 模块的文档简短易懂(请注意,它仅在 github 页面中提供)。其他两个备选方案可以用于需要更多代码自定义的其他项目。
要设置 firebase,您需要转到 firebase console first and setup a project there, then you will need to create the realtime database, and then go to project overview to get the details(refer to pyrebase docs to understand which details you will need, direct link here),您需要在 python 文件中输入该内容以设置连接。
要使用数据库服务,您还需要为其初始化一个对象,如前所述here。
我建议您直接看一下讨论数据保存和检索的 this 部分 pyrebase 文档。