[英]Converting CURL Command to Python 2.7
我有一個curl命令,可以很好地工作,並給我一個HTTP 200。
curl -i -H "Authorization: Basic jadkfhjkafDSKJ12DD=" http://<ip>/LoadTest/rest/authentication-point/authenticate
上面的API需要base64
格式的授權,並且詳細信息必須作為Header傳遞。 這是一個GET請求。
當我嘗試在Python 2.7中運行相同代碼時,得到Response [403]
。 下面的代碼。
import requests
headers = {'Authorization': 'Basic jadkfhjkafDSKJ12DD='}
authurl = "http://<ip>/LoadTest/rest/authentication-point/authenticate"
r = requests.get(authurl, headers=headers)
print r.status_code
我在這里想念什么? 我應該如何像在curl命令中傳遞的那樣傳遞授權值? 我已經嘗試了多種方法,但仍然總是總是得到HTTP 403。 請指導。
感謝大家的投入。 這是最終的解決方案。 我發現有代理正在停止有效負載。 因此,將會話添加到請求中。
import requests
session = requests.Session()
session.trust_env = False
headers = {'Authorization': 'Basic jadkfhjkafDSKJ12DD='}
authurl = "http://<ip>/LoadTest/rest/authentication-point/authenticate"
r = session.get(authurl, headers=headers)
print r.status_code
設置trust_env=False
忽略以下內容:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.