使用SST Web测试框架时遇Python报错NameError: 'StandardError'未定义求助
NameError: name 'StandardError' is not defined in SST Web Test Framework (Python 3.6.4) Hey there! I’ve dealt with similar Python 2 vs 3 compatibility headaches before, so let’s get this sorted for you.
Why this error pops up
The StandardError class was a core exception type in Python 2, but it got fully removed in Python 3—replaced by the base Exception class instead. Since SST 0.2.4 was built with Python 2 in mind, its code still references StandardError, which your Python 3.6.4 interpreter doesn’t recognize at all.
Step-by-step fix
Here’s how to update the SST code to play nice with Python 3:
- Find where SST is installed: Run this command in your terminal to get the installation path:
pip show sst | grep Location - Track down files with
StandardError: Head to the SST directory, then use a search tool to find all instances of the outdated class. For Linux/macOS:
For Windows PowerShell:grep -r "StandardError" /path/to/sst/installationGet-ChildItem -Path "C:\path\to\sst\installation" -Recurse | Select-String -Pattern "StandardError" - Replace
StandardErrorwithException: Open each file that has the reference, swap every occurrence ofStandardErrorwithException. This works becauseExceptionin Python 3 does exactly whatStandardErrordid in Python 2—it’s the base class for all non-system-exit exceptions. - Save and re-run: Once all updates are done, fire up your SST test code again. The
NameErrorshould be gone.
Alternative (no source code edits)
If you’d rather not tweak the SST package directly, you could run your tests using Python 2.7 instead—since StandardError is natively supported there. Just set up a Python 2.7 environment and install SST there to avoid conflicts with your Python 3 setup.
内容的提问来源于stack exchange,提问作者Amol Kumbhar

