Repository: plotly/plotly.py

Issue:
Stream TypeError: 'str' does not support the buffer interface
Hello.

When I try [this](http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming_p1-first-stream.ipynb) code I get an error in rendering Cell number 11:

```
TypeError: 'str' does not support the buffer interface
```

I guess it's because I'm running `Python 3.4`. Since Python 3 there is necessary to treat bytes and unicodes differently.



Discussion:
I confirm this bug on Python 3.4. 

Thanks for reaching out to us.


Resolving patch:
diff --git a/plotly/plotly/chunked_requests/chunked_request.py b/plotly/plotly/chunked_requests/chunked_request.py
--- a/plotly/plotly/chunked_requests/chunked_request.py
+++ b/plotly/plotly/chunked_requests/chunked_request.py
@@ -61,7 +61,7 @@ def write(self, data, reconnect_on=('', 200, )):
             msglen = format(len(msg), 'x')  # msg length in hex
             # Send the message in chunk-encoded form
             self._conn.send('{msglen}\r\n{msg}\r\n'
-                            .format(msglen=msglen, msg=msg))
+                            .format(msglen=msglen, msg=msg).encode('utf-8'))
         except http_client.socket.error:
             self._reconnect()
             self.write(data)
@@ -84,7 +84,7 @@ def _connect(self):
         # Set blocking to False prevents recv
         # from blocking while waiting for a response.
         self._conn.sock.setblocking(False)
-        self._bytes = ''
+        self._bytes = six.b('')
         self._reset_retries()
         time.sleep(0.5)
 
@@ -103,7 +103,7 @@ def close(self):
         # For some reason, either Python or node.js seems to
         # require an extra \r\n.
         try:
-            self._conn.send('\r\n0\r\n\r\n')
+            self._conn.send('\r\n0\r\n\r\n'.encode('utf-8'))
         except http_client.socket.error:
             # In case the socket has already been closed
             return ''
@@ -123,21 +123,21 @@ def _getresponse(self):
         response = self._bytes
         while True:
             try:
-                bytes = self._conn.sock.recv(1)
+                _bytes = self._conn.sock.recv(1)
             except http_client.socket.error:
                 # For error 54: Connection reset by peer
                 # (and perhaps others)
-                return ''
-            if bytes == '':
+                return six.b('')
+            if _bytes == six.b(''):
                 break
             else:
-                response += bytes
+                response += _bytes
         # Set recv to be non-blocking again
         self._conn.sock.setblocking(False)
 
         # Convert the response string to a http_client.HTTPResponse
         # object with a bit of a hack
-        if response != '':
+        if response != six.b(''):
             # Taken from
             # http://pythonwise.blogspot.ca/2010/02/parse-http-response.html
             try:
@@ -145,7 +145,7 @@ def _getresponse(self):
                 response.begin()
             except:
                 # Bad headers ... etc.
-                response = ''
+                response = six.b('')
         return response
 
     def _isconnected(self):
@@ -173,7 +173,7 @@ def _isconnected(self):
             # 3 - Check if the server has returned any data.
             # If they have, then start to store the response
             # in _bytes.
-            self._bytes = ''
+            self._bytes = six.b('')
             self._bytes = self._conn.sock.recv(1)
             return False
         except http_client.socket.error as e:


Test patch: