最近本站的部署脚本执行报错:

1
2
3
4
5
6
Traceback (most recent call last):
File "/usr/local/bin/coscmd", line 5, in <module>
from coscmd.cos_cmd import _main
File "/usr/local/lib/python3.12/dist-packages/coscmd/cos_cmd.py", line 2, in <module>
from six.moves.configparser import SafeConfigParser
ImportError: cannot import name 'SafeConfigParser' from 'configparser' (/usr/lib/python3.12/configparser.py). Did you mean: 'RawConfigParser'?

核心问题在于尝试从configparser模块导入SafeConfigParser时失败了。

原因是使用的腾讯云coscmd命令行工具,因为要兼容Python 2.x版本,在pip上最新版本停更于1.8.6.34。Python 3.12 之后,SafeConfigParser已经被移除,应该使用ConfigParser

搞清楚原因就好解决了,直接在 Github Action 脚本中,限制为Python 3.11版本即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install tencent cloud coscmd
run: |
python -m pip install --upgrade pip
pip install coscmd

- name: Configuration tencent cloud coscmd
env:
SECRET_ID: ${{ secrets.TENCENT_CLOUD_SECRET_ID }}
SECRET_KEY: ${{ secrets.TENCENT_CLOUD_SECRET_KEY }}
BUCKET: ${{ secrets.COS_BUCKET }}
REGION: ${{ secrets.COS_REGION }}
run: |
coscmd config -a $SECRET_ID -s $SECRET_KEY -b $BUCKET -r $REGION

- name: upload tencent cloud COS
run: |
coscmd upload -rfs --delete ./public/ /

收工~