How to use Python to send data to logstash

I use Python2.7 send data to the logstash above, the use of ordinary TCP port data transmission.

msgDict["@metadata"] = {
"beat":"python-test",
"type":"python"
}
msgDict["@timestamp"] = time.strftime("%Y-%m-%dT%H:%M:%S",now)
msgDict["tags"] = ["python","192.168.4.15"]
msgDict["type"] = "python"

tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("127.0.0.1", 5044)
tcpsock.connect(server_address)
msg = dumps(msgDict) + "\n"
tcpsock.sendall(msg)
tcpsock.close()

But logstash accepted after the show format is not correct, what is
the reason for the formation of.Lumberjack_formatter-0.1.4 also
installed

[33mBeats Input: Remote connection closed {:peer=>"192.168.59.198:64911", :exception=>#Lumberjack::Beats::Connection::ConnectionClosed: Lumberjack::Beats::Connection::ConnectionClosed wrapping: Lumberjack::Beats::Parser::UnsupportedProtocol, unsupported protocol 123>, :level=>:warn}

[33mBeats Input: Remote connection closed {:peer=>"127.0.0.1:56536", :exception=>#Lumberjack::Beats::Connection::ConnectionClosed: Lumberjack::Beats::Connection::ConnectionClosed wrapping: Lumberjack::Beats::Parser::UnsupportedProtocol, unsupported protocol 123>, :level=>:warn}

[33mBeats Input: Remote connection closed {:peer=>"127.0.0.1:58986", :exception=>#Lumberjack::Beats::Connection::ConnectionClosed: Lumberjack::Beats::Connection::ConnectionClosed wrapping: Lumberjack::Beats::Parser::UnsupportedProtocol, unsupported protocol 39>, :level=>:warn}

logstash configure file content
input {
beats {
port => 5044
}
}

Logstash both to accept the beat source data, but also want to let him accept user defined data

Thanks

Don't use a beats input, use a tcp input (or a udp input if you prefer to send the logs over UDP).

Thank you very much for your answer.

If you use tcp/udp, then send the past data as a field (message), or to create multiple fields in logstash filter. I want to send according to the content, generating a plurality of fields, similar to (topbeat),

Sure. Send the log message as JSON (like you attempted to above) and use a json codec on the receiving end.

input {
  tcp {
    ...
    codec => json
  }
}

Thanks very much

input {
tcp {
port => 5040
codec => json
}
beats {
port => 5044
}
}