I am trying to run a custom script when Blender starts.

My script location is

C:\Program Files (x86)\Blender Foundation\Blender\2.70\scripts\startup

My idea is to start a TCP server on Blender start up, but Blender is complaining:

NameError: name 'register' is not defined

This is my script:

import bpy
import socketserver

class MyTCPHandler(socketserver.BaseRequestHandler):

def handle(self):
    # self.request is the TCP socket connected to the client
    self.data = self.request.recv(1024).strip()
    print("{} wrote:".format(self.client_address[0]))
    # just send back the same data, but upper-cased

def register():

def unregister():

if __name__ == "__main__":


    # Create the server, binding to localhost on port 9999
    server = socketserver.TCPServer(("localhost", 9999), MyTCPHandler)

    # Activate the server; this will keep running until you
    # interrupt the program with Ctrl-C

1 Answer 1


The script has a few issues, first indentation seems not correct and seems to cause the error (could be caused by copy and paste).

Python relies on the indentation of code because it doesn't use braces to separate code segments syntactically.

Before a class can be registered as an operator the class must be inherit from bpy.types.Operator or bpy.types.Menu (see the docs whether there're more options).

The socketserver constructor is not invoked.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.