ValueError:无效宽度0(必须为> 0)

问题描述 投票:0回答:1

我正在尝试在ArchLinux容器docker中使用Expect脚本,但收到错误反馈:

spawn protonvpn init
[ -- PROTONVPN-CLI INIT -- ]

Traceback (most recent call last):
  File "/usr/sbin/protonvpn", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 73, in main
    cli()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 96, in cli
    init_cli()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 212, in init_cli
    print(textwrap.fill(line, width=term_width))
  File "/usr/lib/python3.8/textwrap.py", line 391, in fill
    return w.fill(text)
  File "/usr/lib/python3.8/textwrap.py", line 363, in fill
    return "\n".join(self.wrap(text))
  File "/usr/lib/python3.8/textwrap.py", line 354, in wrap
    return self._wrap_chunks(chunks)
  File "/usr/lib/python3.8/textwrap.py", line 248, in _wrap_chunks
    raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width 0 (must be > 0)
send: spawn id exp6 not open
    while executing
"send "$env(ID)\r""
    (file "/sbin/protonvpnActivate.sh" line 5)

但是当我在linux容器中手动运行它时,一切进行得很好。

[root@e2c097bb81ed /]# /usr/bin/expect /sbin/protonvpnActivate.sh

spawn protonvpn init
                                                               [ -- PROTONVPN-CLI INIT -- ]

ProtonVPN uses two different sets of credentials, one for the website and official apps where the username is most likely your e-mail, and one for
connecting to the VPN servers.

You can find the OpenVPN credentials at https://account.protonvpn.com/account.

--- Please make sure to use the OpenVPN credentials ---

Enter your ProtonVPN OpenVPN username: 
Enter your ProtonVPN OpenVPN password: 
Confirm your ProtonVPN OpenVPN password: 

Please choose your ProtonVPN Plan
1) Free
2) Basic
3) Plus
4) Visionary

Your plan: 3

Choose the default OpenVPN protocol.
OpenVPN can act on two different protocols: UDP and TCP.
UDP is preferred for speed but might be blocked in some networks.
TCP is not as fast but a lot harder to block.
Input your preferred protocol. (Default: UDP)

1) UDP
2) TCP

Your choice: 1

You entered the following information:
Username: xxx
Password: xxxxxx
Tier: Plus
Default protocol: UDP

Is this information correct? [Y/n]: Y
Writing configuration to disk...

Done! Your account has been successfully initialized.

这是启动脚本,使用期望命令:

#!/usr/bin/expect

spawn protonvpn init
expect "username:"
send "$env(ID)\r"
expect "password:"
send "$env(PASSWORD)\r"
expect "password:"
send "$env(PASSWORD)\r"
expect "plan:"
send "3\r"
expect "choice:"
send "1\r"
expect "correct?"
send "Y\r"
expect eof

这是docker-compose.yml:

version: "3.7"
services:
     protonvpn:
       image: protonvpn:archlinux_template
       environment:
         - ID=***
         - PASSWORD=******
       volumes:
         - "/opt/protonvpn/entrypoint.sh:/sbin/entrypoint.sh:rw"
         - "/opt/protonvpn/protonvpnActivate.sh:/sbin/protonvpnActivate.sh:rw"
       entrypoint: ["/bin/bash", "/sbin/entrypoint.sh"]
       cap_add:
         - NET_ADMIN
       devices:
         - /dev/net/tun
       stdin_open: true
       privileged: true
       restart: unless-stopped

预先,谢谢您能提供的所有帮助。

docker docker-compose expect archlinux
1个回答
0
投票

似乎脚本正在尝试读取终端宽度,但是终端宽度为0。也许尝试将tty: true添加到docker-compose,如下所示:

version: "3.7"
services:
     protonvpn:
       image: protonvpn:archlinux_template
       environment:
         - ID=***
         - PASSWORD=******
       volumes:
         - "/opt/protonvpn/entrypoint.sh:/sbin/entrypoint.sh:rw"
         - "/opt/protonvpn/protonvpnActivate.sh:/sbin/protonvpnActivate.sh:rw"
       entrypoint: ["/bin/bash", "/sbin/entrypoint.sh"]
       cap_add:
         - NET_ADMIN
       devices:
         - /dev/net/tun
       stdin_open: true
       tty: true
       privileged: true
       restart: unless-stopped
© www.soinside.com 2019 - 2024. All rights reserved.