在我們的 Locust 腳本中,我們有一個標準化的格式,我們遵循 self.client.post。在這種格式下,我無法讓這個帖子請求作業:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
with self.client.post("/apis/authentication/login", name=f'login-{self.client.userrole} || /apis/authentication/login', data=string, headers=auth_headers, catch_response=True) as r:
我嘗試使用不同的格式,它確實適用于相同的請求:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
requests.post("https://xyz.xyz.com//apis/authentication/login", data=string, headers=auth_headers)
在第一種格式的情況下,完整的 URL 是從標頭傳遞的,我可以看到它正在嘗試訪問正確的地址。在第二種格式中,它無法從標題中獲取它,我添加了它。但這似乎不是問題所在。
我收到的錯誤是:錯誤請求
您的瀏覽器發送了此服務器無法理解的請求。
我認為這與 loginCreds 資料的傳遞方式有關。我們應該在 self.client.post 格式中做些什么來讓它正確傳遞嗎?
uj5u.com熱心網友回復:
我要嘗試的第一件事是將完整的 URL 放在self.client.post路由中。就像你為requests.post.
您還可以從回應物件中獲取最終請求資訊。使用它來比較實際發送的內容。
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
r = self.client.post("/apis/authentication/login", name=f'login-{self.client.userrole} || /apis/authentication/login', data=string, headers=auth_headers)
print(r.request.url)
print(r.request.headers)
print(r.request.body)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/440135.html
