[Python] How to normally output a path containing non-English characters in Popen

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    it's my function code

    ~~~~sql
    DO
    $$
    from subprocess import PIPE,Popen
    import os
    import sys

    env = os.environ.copy()
    reload(sys)
    sys.setdefaultencoding('utf-8')
    plpy.notice(sys.getdefaultencoding())
    command = 'hdfs dfs -ls /workspace/테스트/'
    ls = Popen(command, shell=True, stdout= PIPE, stderr=PIPE, env=env)
    stdout,stderr = ls.communicate()
    plpy.notice(stdout)
    $$ LANGUAGE plpythonu


    the corresponding error is output.

    ls: '/workspace/??????' : No such file or directory


    No matter how many times you try encoding or decoding, the file name is broken only in Hadoop's command.

    ex)mkdir -p 테스트 like a works well in console

    plpythonu's python version : 2.7

    Continue reading...

Compartilhe esta Página