AttributeError 'nonetype' object has no attribute 'recv'
<p>First of all I need to say I've never tried coding in python before... </p>

<p>I'm trying to make a Twitch IRC bot working but I keep failing... </p>

<p>My bot.py code looks like this: </p>

<pre><code>from src.lib import irc as irc_

from src.lib import functions_general

from src.lib import functions_commands as commands

from src.config import config

class PartyMachine:

    def __init__(self, config):
        self.config = config
        self.irc = irc_.irc(config)
        self.socket = self.irc.get_irc_socket_object()


    def sock(self):
        irc = self.irc
        sock = self.socket
        config = self.config
        kage = sock

        while True:
            data = sock.recv(2048).rstrip()

            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print (data)
</code></pre>

<p>my config.py is here:</p>

<pre><code>'socket_buffer_size': 1024
</code></pre>

<p>My irc.py is here:</p>

<pre><code>def get_irc_socket_object(self):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(10)

    self.sock = sock

    try:
        sock.connect((self.config['server'], self.config['port']))
    except:
        pp('Cannot connect to server (%s:%s).' % (self.config['server'], self.config['port']), 'error')
        sys.exit()

    sock.settimeout(None)
def sock_send(sock, send, self):
    sock.send('USER %s\r\n' % self.config['username'], sock.encode('utf-8'), send.encode('utf-8'))
    sock.send('PASS %s\r\n' % self.config['oauth_password'])
    sock.send('NICK %s\r\n' % self.config['username'])

    if self.check_login_status(sock.recv(1024)):
        pp('Login successful.')
    else:
        pp('Login unsuccessful. (hint: make sure your oauth token is set in self.config/self.config.py).', 'error')
        sys.exit()
</code></pre>

<p>and my serve.py is here:</p>

<pre><code>from sys import argv
from src.bot import *
from src.config.config import *

bot = PartyMachine(config).sock()
</code></pre>

<p>It keeps failing with "<code>AttributeError 'nonetype' object has no attribute 'recv'</code>". How can this be ? </p>

<p>Your <code>get_irc_socket_object(self)</code> might be the problem. You call it with the line <code>self.socket = self.irc.get_irc_socket_object()</code>. This means that python expects the function <code>get_irc_socket_object(self)</code> to return a socket object, but you don't return anything (you just write <code>self.sock = sock</code>, which doesn't do anything because you use <code>self.socket</code> for the rest of your code). As a result, the function returns <code>none</code>, so now <code>self.socket</code> just has that as its value. Therefore, when you make the call to recv you get your error</p>

<p>Also, please clean up your variable names. Sock is used way too often in your code and makes it very hard to follow.</p>

python python-3.x