【问题标题】:ValueError: invalid width 0 (must be > 0)ValueError:无效宽度 0(必须 > 0)
【发布时间】:2020-04-01 14:11:08
【问题描述】:

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

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。也许尝试将 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
    

    还有一个可能相关的旧 docker 错误:https://github.com/moby/moby/issues/33794

    如果这是问题,请将您的环境部分编辑为以下内容:

    environment:
        - COLUMNS=`tput cols`
        - LINES=`tput lines`
        - ID=***
        - PASSWORD=******
    

    【讨论】:

    • 好的,我尝试添加环境和 TTY 但没有改变
    • 好的,您可能想了解我链接的 docker 问题中的一些提示,其中很多是手动调整终端的大小,您可以将其添加到您的脚本中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2020-04-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多