blueset
V2EX  ›  问与答

[Q] Apache → PHP → shell_exec → Python 3 → sys.argv 的过程中出现的奇怪的编码问题。

  •  
  •   blueset · Jan 12, 2017 · 1309 views
    This topic created in 3408 days ago, the information mentioned may be changed or developed.

    用 PHP 的 shell_exec 调用 Python 脚本。

    demo.php

    echo shell_exec("python3 demo.py 学校");
    

    demo.py

    import sys
    print(sys.argv)
    

    在 SSH 终端里面运行的时候 (php demo.php)显示的是正常的内容。

    ['demo.py', '学校']
    

    但是从浏览器里面访问的时候,每个字节前面直接给插入了一个 \xDC

    ['demo.py', '\udce5\udcad\udca6\udce6\udca0\udca1']
    

    求解答。

    尝试过各种 set_locale 设置均已失败。

    联动 https://stackoverflow.com/questions/41594340/bad-unicode-encoding-in-apache-%E2%86%92-php-%E2%86%92-shell-exec-%E2%86%92-python-3-%E2%86%92-sys-argv

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3859 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 260ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    ♥ Do have faith in what you're doing.