我正在尝试访问只允许输入的网络部分,如果我已登录,我已登录。但是当我尝试输入另一个网址时,网络会阻止我使用代码403。
我一直在阅读我登录后可以使用cookie来保持会话开放。但是我无法保持会话开放。
使用python 3和recuests库:
代码:
import requests
url = "https://webpage.com/auth/login"
username = 'user'
password = 'otherpass'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'Keep-Alive',
'Content-Type': 'text/html; charset=UTF-8',
'Referer': url}
session = requests.Session()
session.get(url)
session_login = session.post(url, auth=(username, password), headers=headers)
print(session.cookies)
print(session_login.status_code)
url = 'https://webpage.com/other/492402'
r = session.get(url)
print(r.status_code)
响应>>> RequestsCookieJar [用于曲奇__cfduid = d8464a0ea441b8b1710574d14a6c2163a1488734431 /,饼干webpage_session = eyJpdiI6IldrbVwvVk1xb0xWTWlZOE1GWFFMV0pvZVBkQlRjNHdMTXUrVEdCXC9sTEZIOD0iLCJ2YWx1ZSI6InVtaHpZR1RlNkt1bHRnOGNhR3NuYXIrM0czN0NnOXpYK2FBbEllOUw2YThOTlRkYzFyVTBPbFFSRXdjXC90ZDM4eVlSTkhub3BcL0dsYzk1aFhQZWtBYXc9PSIsIm1hYyI6ImM4NDA5YmE0NmRmZmI2ZGM1ODAyZWQ0NDE4MGQ0N2RlMDNiOTAzOGE4NzRiNTcwY2RjNTJmMDQyMjAxMGVlMGIifQ%3D%3D webpage.com /
响应>>> 200
响应>>> 403
如何在创建上一个会话时发送另一个请求?