单位装了个打卡.机有python大佬与我沟通的吗?
import sys
sys.path.append("C:\\Users\\fcg\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python312\\site-packages")
import requests
# 定义目标URL、用户名和密码
url = 'http://172.16.50.29:4370' # 使用TCP通讯端口4370
username = '1' # 示例用户名
password = '7427' # 示例密码
# 由于没有提供代理服务器的需求,这里我们不使用代理,直接连接
# 如果您的网络环境需要通过代理连接,您需要像之前一样配置代理服务器信息
try:
# 发送带有基本认证的GET请求
response = requests.get(url, auth=(username, password), timeout=10)
# 打印响应的状态码和内容
print(f'Status Code: {response.status_code}')
print(f'Response Text: {response.text}')
except requests.exceptions.ConnectionError as e:
print("连接错误,请检查您的URL或网络状态。")
print(e)
except requests.exceptions.Timeout as e:
print("请求超时,请检查您的连接或服务器状态。")
print(e)
except requests.exceptions.RequestException as e:
print("请求过程中出现错误。")
print(e)
这是测试连接
连接错误,请检查您的URL或网络状态。
('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))