~ballot/turku/turku-agent

« back to all changes in this revision

Viewing changes to turku_agent/ping.py

  • Committer: Ryan Finnie
  • Date: 2020-03-23 22:50:45 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: ryan@finnie.org-20200323225045-hq8rd3gl1lca5014
Move encoding from writes to opens

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
def call_ssh(config, storage, ssh_req):
42
42
    # Write the server host public key
43
 
    t = tempfile.NamedTemporaryFile()
 
43
    t = tempfile.NamedTemporaryFile(mode='w+', encoding='UTF-8')
44
44
    for key in storage['ssh_ping_host_keys']:
45
 
        t.write(('%s %s\n' % (storage['ssh_ping_host'], key)).encode('UTF-8'))
 
45
        t.write('%s %s\n' % (storage['ssh_ping_host'], key))
46
46
    t.flush()
47
47
 
48
48
    # Call ssh
60
60
        storage['ssh_ping_host'],
61
61
        'turku-ping-remote',
62
62
    ]
63
 
    p = subprocess.Popen(ssh_command, stdin=subprocess.PIPE)
 
63
    p = subprocess.Popen(ssh_command, stdin=subprocess.PIPE, encoding='UTF-8')
64
64
 
65
65
    # Write the ssh request
66
 
    p.stdin.write((json.dumps(ssh_req) + '\n.\n').encode('UTF-8'))
 
66
    p.stdin.write(json.dumps(ssh_req) + '\n.\n')
67
67
    p.stdin.flush()
68
68
 
69
69
    # Wait for the server to close the SSH connection