Coding noob TypeError: 'str' does not support the buffer interface
<p>I have absolutely no experience with Python and very very little with any other coding languages. However, a few days ago I discovered a tutorial on how to make a "Twitch Plays" stream on twitch.tv. The last step in that process is to mess with some Python code that you copy and paste off of pastebin.com. I'm 99% sure I've done all steps up until this point correctly, but I'm getting two error codes in two separate files. I apologize if I post more than is needed, I don't know what's relevant or necessary.</p>

<p>The first file "Main" is giving the error message:</p>

<p>Sending our details to twitch...
Traceback (most recent call last):
  File Location, line 11, in 
    t.twitch_connect(username, key);</p>

<pre><code>1    #Define the imports
2    import twitch
3    import keypresser
4    t = twitch.Twitch();
5    k = keypresser.Keypresser();
6     
7    #Enter your twitch username and oauth-key below, and the app connects to twitch with the details.
8    #Your oauth-key can be generated at http://twitchapps.com/tmi/
9    username = "dbproxy";
10    key = "I put my OauthKey here in the real file";
11    t.twitch_connect(username, key);
12     
13    #The main loop
14    while True:
15        #Check for new mesasages
16        new_messages = t.twitch_recieve_messages();
17     
18        if not new_messages:
19            #No new messages...
20            continue
21        else:
22            for message in new_messages:
23                #Wuhu we got a message. Let's extract some details from it
24                msg = message['message'].lower()
25                username = message['username'].lower()
26                print(username + ": " + msg);
27     
28                #This is where you change the keys that shall be pressed and listened to.
29                #The code below will simulate the key q if "q" is typed into twitch by someone
30                #.. the same thing with "w"
31                #Change this to make Twitch fit to your game!
32                if msg == "q": k.key_press("q");
33                if msg == "w": k.key_press("w");
</code></pre>

<p>The second file "Twitch" is giving this error message:</p>

<p>File Location, line 30, in twitch_connect
    s.send('USER %s\r\n' % user);
TypeError: 'str' does not support the buffer interface</p>

<p>and the code is:</p>

<pre><code>1    import socket
2    import sys
3    import re
4     
5    class Twitch:
6     
7        user = "";
8        oauth = "";
9        s = None;
10     
11        def twitch_login_status(self, data):
12            if not re.match(r'^:(testserver\.local|tmi\.twitch\.tv) NOTICE \* :Login unsuccessful\r\n$', data): return True
13            else: return False
14     
15        def twitch_connect(self, user, key):
16            self.user = user;
17            self.oauth= key;
18            print("Connecting to twitch.tv");
19            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
20            s.settimeout(0.6);
21            connect_host = "irc.twitch.tv";
22            connect_port = 6667;
23            try:
24                s.connect((connect_host, connect_port));
25            except:
26                print("Failed to connect to twitch");
27                sys.exit();
28            print("Connected to twitch");
29            print("Sending our details to twitch...");
30            s.send('USER %s\r\n' % user);
31            s.send('PASS %s\r\n' % key);
32            s.send('NICK %s\r\n' % user);
33     
34            if not self.twitch_login_status(s.recv(1024)):
35                print("... and they didn't accept our details");
36                sys.exit();
37            else:
38                print("... they accepted our details");
39                print("Connected to twitch.tv!")
40                self.s = s;
41                s.send('JOIN #%s\r\n' % user)
42                s.recv(1024);
43     
44        def check_has_message(self, data):
45            return re.match(r'^:[a-zA-Z0-9_]+\![a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\.tmi\.twitch\.tv|\.testserver\.local) PRIVMSG #[a-zA-Z0-9_]+ :.+$', data)
46     
47        def parse_message(self, data):
48            return {
49                'channel': re.findall(r'^:.+\![a-zA-Z0-9_]+@[a-zA-Z0-9_]+.+ PRIVMSG (.*?) :', data)[0],
50                'username': re.findall(r'^:([a-zA-Z0-9_]+)\!', data)[0],
51                'message': re.findall(r'PRIVMSG #[a-zA-Z0-9_]+ :(.+)', data)[0].decode('utf8')
52            }
53     
54        def twitch_recieve_messages(self, amount=1024):
55            data = None
56            try: data = self.s.recv(1024);
57            except: return False;
58     
59            if not data:
60                print("Lost connection to Twitch, attempting to reconnect...");
61                self.twitch_connect(self.user, self.oauth);
62                return None
63     
64            #self.ping(data)
65     
66            if self.check_has_message(data):
67                return [self.parse_message(line) for line in filter(None, data.split('\r\n'))];
</code></pre>

<p>I apologize both for how long this post is, and because something tells me this is a very simple problem.</p>

<p>I do have one last question if somebody doesn't mind answering it though.</p>

<p>I've already messed around with the code more than I feel comfortable, I'm shocked there aren't more error message to be honest, but I'm fairly certain that in the first file "Main" I'm supposed to modify:</p>

<pre><code>    #Wuhu we got a message. Let's extract some details from it
    msg = message['message'].lower()
    username = message['username'].lower()
    print(username + ": " + msg);
</code></pre>

<p>I think I'm supposed to change ['message'], ['username'] and inbetween the quotes on the third line because the text in those places is orange, and so far everything I've been supposed to touch was orange on the "Main" file, but I have no clue what that part does, or why I would change those parts, I've gone over the tutorial 10 or so times and it doesn't explain it, is it obvious to people who know what those codes mean and do?</p>

<p>Any and all help is very much appreciated, thank you in advance.</p>