我想建立一个持久会话,我可以不断地对服务器发出某些请求。我的第一步是简单地建立一个持久会话,但是当我使用Session()时,我得到404状态代码,如果我使用request.get()函数,它可以正常工作。
这是我的代码:
import requests
from requests.auth import HTTPBasicAuth
url = "http://192.168.100.107/public/v1/state/User"
username = "admin"
password = "password"
#response = requests.get(url, verify=False, auth=HTTPBasicAuth(username, password))
session = requests.Session()
session.auth = ("admin", "password")
response = session.get(url)
status_code = response.status_code
print(status_code)