av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Python requests HTTP驗(yàn)證登錄實(shí)現(xiàn)流程

瀏覽:4日期:2022-07-06 11:15:06

1、場景

1)用戶輸入完網(wǎng)址后,瀏覽器直接彈出需要輸入用戶名/密碼

Python requests HTTP驗(yàn)證登錄實(shí)現(xiàn)流程

PS:此時(shí)輸入用戶名密碼即可登錄,或者直接帶著用戶名密碼訪問網(wǎng)站。

假設(shè)url為http://xxx.yyy.zzz

用戶名為admin

密碼為123456

則訪問的網(wǎng)址應(yīng)該為http://admin:123456@xxx.yyy.zzz【http://username:password@url】

直接訪問改網(wǎng)址即可

2)利用requests.get(url)返回狀態(tài)碼為401

# -*- encoding=utf-8 -*-import requestsif __name__ == ’__main__’: url = ’http://xxxxx.yyyyyy’ response = requests.get(url=url) status_code = response.status_code print status_code text = response.text print text

運(yùn)行

401<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/><title>401 - Unauthorized: Access is denied due to invalid credentials.</title><style type='text/css'><!--body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}fieldset{padding:0 15px 10px 15px;} h1{font-size:2.4em;margin:0;color:#FFF;}h2{font-size:1.7em;margin:0;color:#CC0000;} h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:'trebuchet MS', Verdana, sans-serif;color:#FFF;background-color:#555555;}#content{margin:0 0 0 2%;position:relative;}.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}--></style></head><body><div id='header'><h1>Server Error</h1></div><div id='content'> <div class='content-container'><fieldset> <h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2> <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3> </fieldset></div></div></body></html>

2、HTTP基礎(chǔ)驗(yàn)證

這是一種簡單的身份認(rèn)證,它是通過http的authorization請求頭中,攜帶經(jīng)過base64加密的用戶名和密碼而實(shí)現(xiàn)的一種認(rèn)證

# -*- encoding=utf-8 -*-import requestsfrom requests.auth import HTTPBasicAuthif __name__ == ’__main__’: url = ’http://xxx.yyy.zzz’ user = ’admin’ password = ’123456’ response = requests.get(url=url, auth=HTTPBasicAuth(user, password)) # 或者 # response = requests.get(url=url, auth=(user, password)) print response.status_code

3、摘要式身份認(rèn)證

# -*- encoding=utf-8 -*-import requestsfrom requests.auth import HTTPDigestAuthif __name__ == ’__main__’: url = ’http://xxx.yyy.zzz’ user = ’admin’ password = ’123456’ response = requests.get(url, auth=HTTPDigestAuth(user, password)) print response.status_code

如果2和3都不行,還是返回401,此時(shí)可以試試第4種

使用2和3依舊返回401,此時(shí)可以print出response.headers看一下

# -*- encoding=utf-8 -*-import requestsfrom requests.auth import HTTPDigestAuthif __name__ == ’__main__’: url = ’http://xxx.yyy.zzz’ user = ’admin’ password = ’123456’ response = requests.get(url, auth=HTTPDigestAuth(user, password)) print response.status_code print response.headers

運(yùn)行

401{’Content-Length’: ’1293’, ’X-Powered-By’: ’ASP.NET’, ’Server’: ’Microsoft-IIS/7.5’, ’Date’: ’Fri, 05 Jun 2020 05:36:23 GMT’, ’Content-Type’: ’text/html’, ’WWW-Authenticate’: ’Negotiate, NTLM’}

打印后可看到headers中帶有字樣’WWW-Authenticate’: ’Negotiate, NTLM’,表示需要ntlm驗(yàn)證,此時(shí)嘗試使用第4種[/code]

4、ntlm驗(yàn)證

# -*- encoding=utf-8 -*-import requestsfrom requests_ntlm import HttpNtlmAuthif __name__ == ’__main__’: url = ’http://xxx.yyy.zzz’ user = ’admin’ password = ’123456’ response = requests.get(url, auth=HttpNtlmAuth(user, password)) print response.status_code print response.headers

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 成人午夜激情 | 99re视频在线免费观看 | 欧美成人在线网站 | 二区三区av | 国产精品久久精品 | 日韩一区二区福利视频 | 亚洲成网 | 国内自拍偷拍 | 欧美日韩国产精品一区 | 国产精品亚洲成在人线 | 伊人网站在线 | 美女视频一区二区三区 | 波多野结衣一二三区 | 成人国产一区二区三区精品麻豆 | 91福利网| 成人精品一区二区 | 日韩手机在线视频 | 黄片毛片在线观看 | 国产精品欧美一区二区三区不卡 | 99久久精品一区二区毛片吞精 | 日本字幕在线观看 | 91精品久久久久久久久久入口 | 999久久久| 五月天天丁香婷婷在线中 | 一区二区亚洲 | 九色www| 亚洲不卡 | 欧美性久久久 | 国产精品视频在线观看 | 久久久久久久av | 亚洲综合国产精品 | 亚洲精品免费在线 | 国产福利在线播放麻豆 | 日韩视频高清 | 亚洲精品aⅴ | 国产精品亚洲第一区在线暖暖韩国 | 国产精品久久久久久久久久三级 | 久久夜视频 | 国产a级毛毛片 | 一区二区不卡视频 | 亚洲天堂久久 |