Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
成功登录会话后Python请求GET失败_Python_Web Scraping - Fatal编程技术网

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

成功登录会话后Python请求GET失败,python,web-scraping,Python,Web Scraping,因此,我使用Python请求库登录到PHP WebCM。到目前为止,我能够使用post命令和有效负载登录。我可以下载一个文件 问题是:当我在通过POST登录后运行GET命令时,它告诉我我不再登录了——尽管我仍然在使用同一个会话!请看一下代码 #Lets Login with requests.session() as s: payload = {'username': strUserName, 'password': strUserPass, 'Submit':'Login'} r = s.po

因此,我使用Python请求库登录到PHP WebCM。到目前为止,我能够使用post命令和有效负载登录。我可以下载一个文件

问题是:当我在通过POST登录后运行GET命令时,它告诉我我不再登录了——尽管我仍然在使用同一个会话!请看一下代码

#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登录。网站注意到我已经登录了,我误解了