# Go2-W SportClient调用SwitchGait报AttributeError缺失属性

> 原文链接：https://robotics.hellobike.com/pitfalls/2026-04-16-unitree-sdk2-python-134
> 频道：pitfalls | 更新日期：2026-04-16 | 标签：auto, github-issue, unitree_sdk2_python
> 核心摘要：Go2-W示例调用SwitchGait报错，因默认SportClient缺该方法，改用b2模块下的SportClient即可解决。

# Go2-W SportClient调用SwitchGait报AttributeError缺失属性

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[[ISSUE] : AttributeError: 'SportClient' object has no attribute 'SwitchGait'](https://github.com/unitreerobotics/unitree_sdk2_python/issues/134)（GitHub unitreerobotics/unitree_sdk2_python #134）

**状态**：已解决

## 问题

在unitree_sdk2_python的go2w_sport_client.py示例中执行switch_gait测试（ID 6）时，调用sport_client.SwitchGait(1)触发AttributeError: 'SportClient' object has no attribute 'SwitchGait'，导致无法切换步态模式，其余测试项正常。

## 环境

机型：Unitree Go2-W；SDK：unitree_sdk2_python；系统：Ubuntu；示例脚本：go2w_sport_client.py；网卡：eth0

## 解决办法

1. 修改导入语句，弃用默认的SportClient，改为从b2模块导入：from unitree_sdk2py.b2.sport.sport_client import SportClient
2. 保持原有sport_client.SwitchGait(1)调用逻辑不变，重新运行go2w_sport_client.py脚本
3. 验证switch_gait测试项（ID 6）不再抛出AttributeError且步态切换功能恢复正常

讨论原作者：@KA1773-akash-pawar 等，版权归原作者所有。
:::

## 原始参考来源 (Sources)

- [GitHub unitreerobotics/unitree_sdk2_python #134：[ISSUE] : AttributeError: 'SportClient' object has no attribute 'SwitchGait'](https://github.com/unitreerobotics/unitree_sdk2_python/issues/134)