Encoding str from utf-8 before sending to socket

pull/1/head
Jadjay 2016-06-21 23:53:18 +02:00
parent c8bd6830ee
commit 85a90e47db
1 changed files with 7 additions and 4 deletions

View File

@ -780,16 +780,19 @@ class ServerConnection(Connection):
"""Send raw string to the server.
The string will be padded with appropriate CR LF.
From here everything need to be encoded in str from utf-8
"""
string=string.encode('utf-8')
if self.socket is None:
raise ServerNotConnectedError, u'Not connected.'
raise ServerNotConnectedError, "Not connected."
try:
if self.ssl:
self.ssl.write(string + u'\r\n')
self.ssl.write(string + "\r\n")
else:
self.socket.send(string + u'\r\n')
self.socket.send(string + "\r\n")
if DEBUG:
print u'TO SERVER:', string
print "TO SERVER:", string
except socket.error, x:
# Ouch!
self.disconnect(u'Connection reset by peer.')