R
R
Roman Zanevsky2020-05-07 21:27:03
linux
Roman Zanevsky, 2020-05-07 21:27:03

Hook script python incorrectly decodes Cyrillic output from linux shell. Where is the mistake?

There is a hook script for python. Here is its main function:

def main(repos):
  log_cmd = '%s log "%s"' % (SVNLOOK, repos)
  log_msg = os.popen(log_cmd, 'r').readline().rstrip('n')
  rev_number_cmd = '%s info "%s"' % (SVNLOOK, repos)
  out = subprocess.Popen(rev_number_cmd, stdout=subprocess.PIPE, shell=True)
  revs = out.stdout.read().decode('UTF-8')
  own_key = check_commit_message(log_msg, jira)
  comment_jira_ticket(jira, own_key, revs)

if __name__ == '__main__':
  main(sys.argv[1])


This script executes the svnlook info command and takes the info of the latest commit in the repository. When using the command in the linux shell, all information is displayed correctly and correctly:
username
2020-05-07 20:53:48 +0300 (Thu, 07 May 2020)
53
ISSUE-148 Win В первом раунде

When the command is called by a script and decoded from utf-8, it turns out:
username
2020-05-07 20:53:48 +0300 (Thu, 07 May 2020)
53
ISSUE-148 Win {U+0412} {U+043F}{U+0435}{U+0440}{U+0432}{U+043E}{U+043C} {U+0440}{U+0430}{U+0443}{U+043D}{U+0434}{U+0435}


Can't handle it: tried decodes from various encodings. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andy_U, 2020-05-08
@Andy_U

Not your case?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question