Python 3.x 理解响应重定向到after post

Python 3.x 理解响应重定向到after post,python-3.x,web-scraping,python-requests,basic-authentication,urllib3,Python 3.x,Web Scraping,Python Requests,Basic Authentication,Urllib3,我一直在试图弄清楚我是如何不正确地使用这段代码的。我以几种不同的方式完成了这项工作,包括使用语句和直接使用urllib3。似乎我试图发布数据,但它登录到重定向或根本不发布,然后总是失败。我在下面列出了代码,以及我检查从chrome和CLI获得的信息的多种方法。就我所知,似乎有一个我处理得不对的回应。你能帮我看看我错过了什么吗 披露:一些信息已经改变了,但应该足够了解发生了什么 import requests import json base = "http://www.XXXXXX.com/

我一直在试图弄清楚我是如何不正确地使用这段代码的。我以几种不同的方式完成了这项工作,包括使用语句和直接使用urllib3。似乎我试图发布数据,但它登录到重定向或根本不发布,然后总是失败。我在下面列出了代码,以及我检查从chrome和CLI获得的信息的多种方法。就我所知,似乎有一个我处理得不对的回应。你能帮我看看我错过了什么吗

披露:一些信息已经改变了,但应该足够了解发生了什么

import requests
import json


base = "http://www.XXXXXX.com/"
url = "http://www.XXXXXX.com/login.php"
scraped_url = "http://www.XXXXXX.com/cart.php?mode=wishlist"
headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36',
            "Connection":"keep-alive",
            "mode":"login",
            "Accept-Language":"en-US, en;q=0.8",
            "Accept-Encoding":"gzip, deflate, sdch",
            "store_language":"en",
            "RefererCookie":"deleted",#http%3A%2F%2Fwww.XXXXXX.com%2Fhome.php
            "Origin":"http://www.XXXXXX.com",
            "Upgrade-Insecure-Requests": "1",
            "P3P": "CP=NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA",
            "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8."
            }


data = {"password":"Reallybadpassword",
            "username":"TheEmail@Gmail.com"}


jar = requests.cookies.RequestsCookieJar()

req = requests.Request('GET', 'http://www.XXXXXX.com/login.php')
r = req.prepare()
s = requests.Session()
s.send(r)
s.headers.update
s.jar.update

r = s.get(base, cookies=jar)
s.headers.update
jar.update
print(r.history)
print(r.status_code)
print(r.url)
print(r.json)
print("################################################################################")
print(r.headers)
print("********************************************************************************")
print(r.cookies)
print("////////////////////////////////////////////////////////////////////////////////")


r = s.post(url, params=data, cookies=jar, allow_redirects=True, headers=headers) #params=values,
s.headers.update
jar.update

print(r.history)
print(r.status_code)
print(r.url)
print(r.json)
print("################################################################################")
print(r.headers)
print("********************************************************************************")
print(r.cookies)
print("////////////////////////////////////////////////////////////////////////////////")


r = s.get(scraped_url, params=data, cookies=jar)
s.headers.update
jar.update

print(r.history)
print(r.status_code)
print(r.url)
print(r.json)
print("################################################################################")
print(r.headers)
print("********************************************************************************")
print(r.cookies)
print("////////////////////////////////////////////////////////////////////////////////")


s.close()

    #####-RESPONSE FROM SITE TO CLI######
    Iam@Groot:/media/Iam/Drive/Backup/Documents/TestWebpages$ python3 login_scraper.py 
    []
    200
    http://www.XXXXXX.com/
    <bound method Response.json of <Response [200]>>
    ################################################################################
    CaseInsensitiveDict({'pragma': 'no-cache', 'server': 'nginx', 'last-modified': '
    Sun, 23 Apr 2017 20:33:45 GMT', 'content-type': 'text/html; charset=iso-8859-1',
     'vary': 'Accept-Encoding', 'p3p': 'CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BU
     S IND PHY ONL UNI PUR COM NAV DEM STA"', 'set-cookie': 'xid_eb442=e8278c9dc379c
     6dfae862b7bf2721138; path=/; domain=www.XXXXXX.com; httponly, RefererCookie=del
     eted; expires=Sat, 23-Apr-2016 20:33:44 GMT; path=/; domain=www.XXXXXX.com; htt
     ponly', 'date': 'Sun, 23 Apr 2017 20:33:45 GMT', 'transfer-encoding': 'chunked'
     , 'expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'connection': 'keep-alive', 'x-po
     wered-by': 'PleskLin', 'cache-control': 'no-store, no-cache, must-revalidate, p
     ost-check=0, pre-check=0', 'content-encoding': 'gzip'})
    ********************************************************************************
    <RequestsCookieJar[<Cookie xid_eb442=e8278c9dc379c6dfae862b7bf2721138 for .www.XXXXXX.com/>]>
    ////////////////////////////////////////////////////////////////////////////////
    []
    200
    http://www.XXXXXX.com/login.php
    <bound method Response.json of <Response [200]>>
    ################################################################################
    CaseInsensitiveDict({'pragma': 'no-cache', 'server': 'nginx', 'last-modified': '
    Sun, 23 Apr 2017 20:33:45 GMT', 'content-type': 'text/html; charset=iso-8859-1',
     'vary': 'Accept-Encoding', 'p3p': 'CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BU
     S IND PHY ONL UNI PUR COM NAV DEM STA"', 'set-cookie': 'xid_eb442=649b55131f4f7
     e9d6958560d3ed406c0; path=/; domain=www.XXXXXX.com; httponly, RefererCookie=del
     eted; expires=Sat, 23-Apr-2016 20:33:44 GMT; path=/; domain=www.XXXXXX.com; htt
     ponly', 'date': 'Sun, 23 Apr 2017 20:33:45 GMT', 'transfer-encoding': 'chunked'
     , 'expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'connection': 'keep-alive', 'x-po
     wered-by': 'PleskLin', 'cache-control': 'no-store, no-cache, must-revalidate, p
     ost-check=0, pre-check=0', 'content-encoding': 'gzip'})
    ********************************************************************************
    <RequestsCookieJar[<Cookie xid_eb442=649b55131695e9ff48560d3ed406c0 for .www.XXXXXX.com/>]>
    ////////////////////////////////////////////////////////////////////////////////
    (<Response [302]>,)
    200
    http://www.XXXXXX.com/login.php
    <bound method Response.json of <Response [200]>>
    ################################################################################
    CaseInsensitiveDict({'pragma': 'no-cache', 'server': 'nginx', 'last-modified': '
    Sun, 23 Apr 2017 20:33:45 GMT', 'content-type': 'text/html; charset=iso-8859-1',
     'vary': 'Accept-Encoding', 'p3p': 'CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BU
     S IND PHY ONL UNI PUR COM NAV DEM STA"', 'set-cookie': 'xid_eb442=649b55131f4f7
     e9d6958560d3ed406c0; path=/; domain=www.XXXXXX.com; httponly, RefererCookie=del
     eted; expires=Sat, 23-Apr-2016 20:33:45 GMT; path=/; domain=www.XXXXXX.com; htt
     ponly', 'date': 'Sun, 23 Apr 2017 20:33:46 GMT', 'transfer-encoding': 'chunked'
     , 'expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'connection': 'keep-alive', 'x-po
     wered-by': 'PleskLin', 'cache-control': 'no-store, no-cache, must-revalidate, p
     ost-check=0, pre-check=0', 'content-encoding': 'gzip'})
    ********************************************************************************
    <RequestsCookieJar[<Cookie xid_eb442=649b55131695e9ff48560d3ed406c0 for .www.XXXXXX.com/>]>
    ////////////////////////////////////////////////////////////////////////////////
    Iam@Groot:/media/Iam/Drive/Backup/Documents/TestWebpages$ 











    #####-FROM CHROME LOGIN-######

    Iam@Groot:~$ sudo ngrep -W byline -d  any -q "XXXXXX"
    interface: any
    match: XXXXXX

    T 192.168.1.5:56250 -> 22.156.106.185:80 [AP]
    POST /login.php HTTP/1.1.
    Host: www.XXXXXX.com.
    Connection: keep-alive.
    Content-Length: 133.
    Cache-Control: max-age=0.
    Origin: http://www.XXXXXX.com.
    Upgrade-Insecure-Requests: 1.
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36.
    Content-Type: application/x-www-form-urlencoded.
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8.
    Referer: http://www.XXXXXX.com/home.php.
    Accept-Encoding: gzip, deflate.
    Accept-Language: en-US,en;q=0.8.
    Cookie: store_language=en; xid_eb442C_remember=TheEmail%40Gmail.com; RefererCookie=http%3A%2F%2Fwww.XXXXXX.com%2Fhome.php; GreetingCookie=Mr.+John+Doe; xid_eb442=649b55131695e9ff48560d3ed406c0.
    .
    xid_eb442=649b55131695e9ff48560d3ed406c0&is_remember=&mode=login&username=TheEmail%40Gmail.com&password=Reallybadpassword

    T 22.156.106.185:80 -> 192.168.1.5:56250 [AP]
    HTTP/1.1 302 Found.
    Server: nginx.
    Date: Sun, 23 Apr 2017 20:03:04 GMT.
    Content-Type: text/html; charset=iso-8859-1.
    Transfer-Encoding: chunked.
    Connection: keep-alive.
    Expires: Mon, 26 Jul 1997 05:00:00 GMT.
    Last-Modified: Sun, 23 Apr 2017 20:03:03 GMT.
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0.
    Pragma: no-cache.
    P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA".
    Set-Cookie: xid_eb442=7e00038d2gd56gtyh73cb97b1225afe; path=/; domain=www.XXXXXX.com; httponly.
    Set-Cookie: GreetingCookie=Mr.+John+Doe; expires=Fri, 20-Oct-2017 20:03:03 GMT; path=/; domain=www.XXXXXX.com; httponly.
    Location: http://www.XXXXXX.com/home.php.
    X-Powered-By: PleskLin.
    .
    d4.
    <br /><br />If the page is not updated in 2 seconds, please follow this link: <a href="http://www.XXXXXX.com/home.php">continue &gt;&gt;</a><meta http-equiv="Refresh" content="0;URL=http://www.XXXXXX.com/home.php" />.


    T 192.168.1.5:56250 -> 22.156.106.185:80 [AP]
    GET /home.php HTTP/1.1.
    Host: www.XXXXXX.com.
    Connection: keep-alive.
    Cache-Control: max-age=0.
    Upgrade-Insecure-Requests: 1.
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36.
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8.
    Referer: http://www.XXXXXX.com/home.php.
    Accept-Encoding: gzip, deflate, sdch.
    Accept-Language: en-US,en;q=0.8.
    Cookie: store_language=en; xid_eb442C_remember=TheEmail%40Gmail.com; RefererCookie=http%3A%2F%2Fwww.XXXXXX.com%2Fhome.php; xid_eb442=7e00038d2gd56gtyh73cb97b1225afe; GreetingCookie=Mr.+John+Doe.
    .


    T 22.156.106.185:80 -> 192.168.1.5:56250 [A]
    HTTP/1.1 200 OK.
    Server: nginx.
    Date: Sun, 23 Apr 2017 20:03:04 GMT.
    Content-Type: text/html; charset=iso-8859-1.
    Transfer-Encoding: chunked.
    Connection: keep-alive.
    Vary: Accept-Encoding.
    Expires: Mon, 26 Jul 1997 05:00:00 GMT.
    Last-Modified: Sun, 23 Apr 2017 20:03:04 GMT.
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0.
    Pragma: no-cache.
    P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA".
    Set-Cookie: xid_eb442=7e00038d2gd56gtyh73cb97b1225afe; path=/; domain=www.XXXXXX.com; httponly.
    X-Powered-By: PleskLin.
    Content-Encoding: gzip.


    T 192.168.1.5:56250 -> 22.156.106.185:80 [AP]
    GET /home.php HTTP/1.1.
    Host: www.XXXXXX.com.
    Connection: keep-alive.
    Cache-Control: max-age=0.
    Upgrade-Insecure-Requests: 1.
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36.
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8.
    Referer: http://www.XXXXXX.com/home.php.
    Accept-Encoding: gzip, deflate, sdch.
    Accept-Language: en-US,en;q=0.8.
    Cookie: store_language=en; xid_eb442C_remember=TheEmail%40Gmail.com; RefererCookie=http%3A%2F%2Fwww.XXXXXX.com%2Fhome.php; xid_eb442=7e00038d2gd56gtyh73cb97b1225afe; GreetingCookie=Mr.+John+Doe.
    .


    T 22.156.106.185:80 -> 192.168.1.5:56250 [A]
    HTTP/1.1 200 OK.
    Server: nginx.
    Date: Sun, 23 Apr 2017 20:03:04 GMT.
    Content-Type: text/html; charset=iso-8859-1.
    Transfer-Encoding: chunked.
    Connection: keep-alive.
    Vary: Accept-Encoding.
    Expires: Mon, 26 Jul 1997 05:00:00 GMT.
    Last-Modified: Sun, 23 Apr 2017 20:03:04 GMT.
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0.
    Pragma: no-cache.
    P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA".
    Set-Cookie: xid_eb442=7e00038d2gd56gtyh73cb97b1225afe; path=/; domain=www.XXXXXX.com; httponly.
    X-Powered-By: PleskLin.
    Content-Encoding: gzip.
导入请求
导入json
基数=”http://www.XXXXXX.com/"
url=”http://www.XXXXXX.com/login.php"
刮取的url=”http://www.XXXXXX.com/cart.php?mode=wishlist"
headers={'User-Agent':'Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/57.0.2987.110 Safari/537.36',
“连接”:“保持活动状态”,
“模式”:“登录”,
“接受语言”:“en-US,en;q=0.8”,
“接受编码”:“gzip、deflate、sdch”,
“存储语言”:“en”,
“RefererCookie”:“已删除”,#http%3A%2F%2Fwww.XXXXXX.com%2Fhome.php
“来源”:http://www.XXXXXX.com",
“升级不安全请求”:“1”,
“P3P”:“CP=非库拉ADMa DEVa TAIa CONi我们的DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA”,
“接受”:“text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8。”
}
数据={“密码”:“Reallybadpassword”,
“用户名”:”TheEmail@Gmail.com"}
jar=requests.cookies.requestScookeJar()
req=请求。请求('GET','http://www.XXXXXX.com/login.php')
r=请求准备()
s=请求。会话()
s、 发送(r)
s、 headers.update
s、 jar.update
r=s.get(base,cookies=jar)
s、 headers.update
jar.update
印刷(r.历史)
打印(r.状态\ U代码)
打印(r.url)
打印(r.json)
3月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日35月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日("""""""")
打印(右标题)
打印(“*************************************************************************************************************************************************************”)
打印(r.cookies)
打印(////////////////////////////////
r=s.post(url,params=data,cookies=jar,allow_redirects=True,headers=headers)#params=value,
s、 headers.update
jar.update
印刷(r.历史)
打印(r.状态\ U代码)
打印(r.url)
打印(r.json)
3月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日35月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日("""""""")
打印(右标题)
打印(“*************************************************************************************************************************************************************”)
打印(r.cookies)
打印(////////////////////////////////
r=s.get(scraped_url,params=data,cookies=jar)
s、 headers.update
jar.update
印刷(r.历史)
打印(r.状态\ U代码)
打印(r.url)
打印(r.json)
3月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日35月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日("""""""")
打印(右标题)
打印(“*************************************************************************************************************************************************************”)
打印(r.cookies)
打印(////////////////////////////////
s、 关闭()
#####-从站点到CLI的响应######
Iam@Groot:/media/Iam/Drive/Backup/Documents/testwebpage$python3 login\u.py
[]
200
http://www.XXXXXX.com/
################################################################################
不区分大小写({'pragma':'no cache','server':'nginx','last modified':'
Sun,2017年4月23日20:33:45 GMT,“内容类型”:“text/html;charset=iso-8859-1”,
‘vary’:‘Accept Encoding’,‘p3p’:‘CP=“NON-CURa ADMa DEVa TAIa CONi OUR DELa BU
S IND PHY ONL UNI PUR COM NAV DEM STA“,“设置cookie”:“xid_eb442=e8278c9dc379c
6dfae862b7bf2721138;路径=/;域=www.XXXXXX.com;httponly,RefererCookie=del
eted;expires=Sat,2016年4月23日20:33:44 GMT;path=/;domain=www.XXXXXX.com;htt
ponly,'日期':'太阳,2017年4月23日20:33:45格林威治标准时间','传输编码':'分块'
“,”过期“:”1997年7月26日星期一05:00:00 GMT“,”连接“:”保持活动“,”x-po
由“:”PleskLin“,”缓存控制“:“无存储,无缓存,必须重新验证,p
ost检查=0,预检查=0,'内容编码':'gzip'})
********************************************************************************
////////////////////////////////////////////////////////////////////////////////
[]
200
http://www.XXXXXX.com/login.php
################################################################################
不区分大小写({'pragma':'no cache','server':'nginx','last modified':'
Sun,2017年4月23日20:33:45 GMT,“内容类型”:“text/html;charset=iso-8859-1”,
‘vary’:‘Accept Encoding’,‘p3p’:‘CP=“NON-CURa ADMa DEVa TAIa CONi OUR DELa BU
S IND PHY ONL UNI PUR COM NAV DEM STA“,”设置cookie“:”xid_eb442=649b55131f4f7
e9d6958560d3ed406c0;路径=/;域=www.XXXXXX.com;httponly,RefererCookie=del
eted;expires=Sat,2016年4月23日20:33:44 GMT;path=/;domain=www.XXXXXX.com;htt
ponly,'日期':'太阳,2017年4月23日20:33:45格林威治标准时间','传输编码':'分块'
“,”过期“:”1997年7月26日星期一05:00:00 GMT“,”连接“:”保持活动“,”x-po
由“:”PleskLin“,”缓存控制“:“无存储,无缓存,必须重新验证,p
ost检查=0,预检查=0,'内容编码':'gzip'})
********************************************************************************
////////////////////////////////////////////////////////////////////////////////
(,)
200
http://www.XXXXXX.com/login.php
################################################################################
不区分大小写({'pragma':'no cache','server':'nginx','last modified':'
Sun,2017年4月23日20:33:45 GMT,“内容类型”:“text/html;charset=iso-8859-1”,
'vary':'Accept Encoding','p3p':'CP=“NON-CURa ADMa DEVa