草庐IT

ftp_login

全部标签

python - 具有多个服务器的 Flask-login 如何工作

我一直在使用Flaskloginmodule,它在服务器上创建和维护session。既然server维护了session,我觉得也不是完全无状态的。当应用程序有多个服务器时它是如何工作的。请求是否应该是粘性的(即给定session应该向特定服务器发出后续请求)? 最佳答案 您所做的陈述并不完全正确:...whichcreatesandmaintainssessionontheserver.Flask-Login使用了Flask提供的session设施,所以它存储在session中的数据将由Flask使用配置的session存储机制写

python - 检查用户是否使用模板中的 Flask-Login 登录

当我让用户登录时,我在session中设置了logged_in,然后在模板中检查这个值。有没有更好的方法来检查用户是否使用Flask-Login登录?session['logged_in']=Truelogin_user(user){%ifsession['logged_in']%}...{%endif%} 最佳答案 引用exampleonflask-login:It’sthatsimple.Youcanthenaccessthelogged-inuserwiththecurrent_userproxy,whichisavailab

python - Python FTP 应用程序中的代理

我正在用Pythonftplib开发一个FTP客户端。如何为其添加代理支持(我见过的大多数FTP应用程序似乎都有)?我特别考虑SOCKS代理,还有其他类型...FTP、HTTP(甚至可以将HTTP代理与FTP程序一起使用吗?)有什么想法吗? 最佳答案 根据this来源。取决于代理,但常用的方法是ftp到代理,然后使用目标服务器的用户名和密码。例如对于ftp.example.com:Serveraddress:proxyserver(oropenproxyserverfromwithftp)User:anonymous@ftp.exa

python - 在 FTP 服务器上扩展 Python 的 os.walk 功能

如何让os.walk遍历FTP数据库(位于远程服务器上)的目录树?现在代码的结构方式是(提供注释):importfnmatch,os,ftplibdeffind(pattern,startdir=os.curdir):#findfunctiontakingvariablesforbothdesiredfileandthestartingdirectoryfor(thisDir,subsHere,filesHere)inos.walk(startdir):#eachofthevariableschangeasthedirectorytreeiswalkedfornameinsubsHer

python - FTP 库错误 : got more than 8192 bytes

Python在上传大小超过8192字节的文件时失败。而异常(exception)只是“得到超过8192个字节”。是否有上传更大文件的解决方案。try:ftp=ftplib.FTP(str_ftp_server)ftp.login(str_ftp_user,str_ftp_pass)exceptExceptionase:print('Connectingftpserverfailed')returnFalsetry:print('Uploadingfile'+str_param_filename)file_for_ftp_upload=open(str_param_filename,'r

python - 使用 flask 登录对 flask 进行单元测试时禁用@login_required

我正在对使用flask-login扩展的Flask应用程序进行单元测试。我正在使用webtest像这样设置我的所有测试:classTestCase(unittest.TestCase):defsetUp(self):app.config['TESTING']=Trueself.client=webtest.TestApp(app)但是当我尝试通过self.client.get()访问带有@login_required修饰的url时,我收到401错误消息,提示我无权访问该url。根据文档https://flask-login.readthedocs.org/en/latest/#prot

python - @login_required Flask 应用程序中的问题

我已经创建了一个处理身份验证的蓝图。此蓝图使用Flask-Login。并具有以下内容以及未显示的更多代码。在蓝图中我有以下内容:fromflask.ext.loginimportLoginManagerfromflask.ext.loginimportUserMixinfromflask.ext.loginimportcurrent_userfromflask.ext.loginimportlogin_requiredfromflask.ext.loginimportlogin_userfromflask.ext.loginimportlogout_userauth_print=Blu

python - 检查 Python FTP 连接

我有一个FTP连接,我正在从中下载许多文件并在中间处理它们。我希望能够检查我的FTP连接是否在两者之间超时。所以代码看起来像这样:conn=FTP(host='blah')conn.connect()foriteminlist_of_items:myfile=open('filename','w')conn.retrbinary('stuff",myfile)###dosomeparsing###如果在###dosomeparsing###行期间超时,我该如何检查我的FTP连接? 最佳答案 发送NOOP命令。这只会检查连接是否仍在进

python - Flask-Login 引发 TypeError : 'bool' object is not callable when trying to override is_active property

我想修改Flask-Login中的is_active,这样用户就不会一直处于事件状态。默认值始终返回True,但我将其更改为返回banned列的值。根据文档,is_active应该是一个属性。但是,内部Flask-Login代码引发:TypeError:'bool'objectisnotcallable尝试使用is_active时。如何正确使用is_active来停用某些用户?classUser(UserMixin,db.Model):id=db.Column(db.Integer,primary_key=True)banned=db.Column(db.Boolean,default

python - 模拟 ftplib.FTP 用于单元测试 Python 代码

我不知道为什么我没有得到这个,但我想在Python中使用mock来测试我的函数是否正确调用了ftplib.FTP中的函数。我已经简化了一切,但仍然没有完全理解它是如何工作的。这是一个简单的例子:importunittestimportftplibfromunittest.mockimportpatchdefdownload_file(hostname,file_path,file_name):ftp=ftplib.FTP(hostname)ftp.login()ftp.cwd(file_path)classTestDownloader(unittest.TestCase):@patch