繁体   English   中英

成功登录会话后,Python请求GET失败

[英]Python Requests GET fails after successfull session login

因此,我正在使用Python Requests库登录到PHP-WebCMS。 到目前为止,我可以使用带有有效负载的后命令登录。 我可以下载文件。

问题是:当我通过POST登录后刚运行GET-Command时,它告诉我即时通讯不再登录-尽管我仍在使用同一会话! 请看一下代码

#Lets Login
with requests.session() as s:
payload = {'username': strUserName, 'password': strUserPass, 'Submit':'Login'}
r = s.post(urlToLoginPHP, data=payload, stream=True)
#Ok we are logged in. If I would run the #DOWNLOADING Files code right here I would get a correct zip file
#But since the r2-Get-Command delivers the "please login" page it doesn't work anymore
r2 = s.get("urlToAnotherPageOfThisWebsite",stream=True)
#We are not logged in anymore

#DOWNLOADING Files: This now just delivers a 5KB big file which contains the content
 of the "please login page"
local_filename = 'image.zip'
# NOTE the stream=True parameter
r1 = s.get(downloadurl, stream=True)
with open(local_filename, 'wb') as f:
    for chunk in r1.iter_content(chunk_size=1024): 
        if chunk: # filter out keep-alive new chunks
            f.write(chunk)
            f.flush()

我找到了解决方案:我登录到浏览器,并试图同时通过python登录。 该站点注意到我已经登录,但我误会了它。

暂无
暂无

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

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