user23283: Currently trying to figure out how to use Python to construct a transaction with OP_RETURN. I tried to encode the message myself, and had no luck. I found a function, OPReturn(), on the internet, but when I attempt to use it, I get the error (from the Blockchain.info broadcast API): Exception: None Standard Script Output OP_RETURN 594f4c4f53574147 
Code:
# coding: utf-8

from bitcoin import *
import binascii
from test import *


priv = sha256('brain wallet')

pub = privtopub(priv)

addr = pubtoaddr(pub)

inputs = unspent(addr)

message = "YOLOSWAG"
FullLen = format(len(message)+2,'x').rjust(2,'0')
MessageLen = format(len(message),'x').rjust(2,'0')
ID = binascii.hexlify(str(message))
snd = "6a"+MessageLen+ID

outputs = [{'value': 50000, 'address': addr}, {'value': 0, 'script': snd}]

fee = 10000

tx = mksend(inputs, outputs, addr, fee)

dt = deserialize(tx)
ins = dt['ins']

#print addr
#print ins


for ind, elm in enumerate(ins):
    print elm
    tx = sign(tx, ind, priv)

#print tx



print(pushtx(tx))


user9382: The script is simply (so to speak) taking a raw transaction and splicing in a hexadecimal number which represents an additional Tx output. So it's looking for ffffffff (sequence) and appending 6a hex encoding of your msg (up to 20 bytes)
The message needs converting to hex (which the code does).
The code works fine for me, although I've yet to try broadcasting. Based on your quoted error 

I get the error (from the Blockchain.info broadcast API): Exception: None Standard Script Output OP_RETURN 594f4c4f53574147

I'd have to say BCI is reacting to theMessageLen part of the code. There should be an OP_PUSHDATA1 (0x4c) between OP_RETURN (0x6a) and the 1 byte msg length, 0x08. 
Try: 6a4c08594f4c4f53574147
Alternatively, try another service to push the raw Tx, eg:

https://insight.bitpay.com/tx/send
https://brainwallet.github.io/#tx


user9382: I have forked the pybitcointools library to return a properly formatted OP_RETURN hex string, or insert the OP_RETURN into a raw hex transaction.
My fork can be found here. The code is as follows:
from bitcoin.pyspecials import safe_hexlify, from_string_to_bytes, from_int_to_byte, from_string_to_bytes

def mk_opreturn(msg, rawtx=None, json=0):
    def op_push(data):
        import struct
        if len(data) < 0x4c:
            return from_int_to_byte(len(data)) + from_string_to_bytes(data)
        elif len(data) < 0xff:
            return from_int_to_byte(76) + struct.pack('<B', len(data)) + from_string_to_bytes(data)
        elif len(data) < 0xffff:
            return from_int_to_byte(77) + struct.pack('<H', len(data)) + from_string_to_bytes(data)
        elif len(data) < 0xffffffff:
            return from_int_to_byte(78) + struct.pack('<I', len(data)) + from_string_to_bytes(data)
        else: raise Exception("Input data error. Rawtx must be hex chars" \
                            + "0xffffffff > len(data) > 0")

    orhex = safe_hexlify(b'\x6a' + op_push(msg))
    orjson = {'script' : orhex, 'value' : 0}
    if rawtx is not None:
        try:
            txo = deserialize(rawtx)
            if not 'outs' in txo.keys(): raise Exception("OP_Return cannot be the sole output!")
            txo['outs'].append(orjson)
            newrawtx = serialize(txo)
            return newrawtx
        except:
            raise Exception("Raw Tx Error!")
    return orhex if not json else orjson

Note that the module name has been changed to btc (from bitcoin) in my fork. 
To run this, you'll use os.chdir("c:/python/pybitcointools") (or whatever directory it's been downloaded to. Then from bitcoin import *. Now, let's use msg = 'The enemy of my enemy is my friend' and rawtx = "01000000016e3cd2b24fcf49259db29888ec5fe6521070041cb8c7bb2017537046f9e00f2b0000000000ffffffff0168d61100000000001976a91469bbbb16301e40b9fb67130e1aa53a2281d60af088ac00000000".
mk_opreturn(msg, rawtx) returns: 
01000000016e3cd2b24fcf49259db29888ec5fe6521070041cb8c7bb2017537046f9e00f2b0000000000ffffffff0268d61100000000001976a91469bbbb16301e40b9fb67130e1aa53a2281d60af088ac0000000000000000246a2254686520656e656d79206f66206d7920656e656d79206973206d7920667269656e6400000000

This is the raw Tx with the OP_RETURN properly inserted. Run the function without the rawtx parameter and it returns the string 6a2254686520656e656d79206f66206d7920656e656d79206973206d7920667269656e64

23283: <p>Currently trying to figure out how to use Python to construct a transaction with OP_RETURN. I tried to encode the message myself, and had no luck. I found a function, OPReturn(), on the internet, but when I attempt to use it, I get the error (from the Blockchain.info broadcast API): <code>Exception: None Standard Script Output OP_RETURN 594f4c4f53574147</code> </p>

<p>Code:</p>

<pre><code># coding: utf-8

from bitcoin import *
import binascii
from test import *


priv = sha256('brain wallet')

pub = privtopub(priv)

addr = pubtoaddr(pub)

inputs = unspent(addr)

message = "YOLOSWAG"
FullLen = format(len(message)+2,'x').rjust(2,'0')
MessageLen = format(len(message),'x').rjust(2,'0')
ID = binascii.hexlify(str(message))
snd = "6a"+MessageLen+ID

outputs = [{'value': 50000, 'address': addr}, {'value': 0, 'script': snd}]

fee = 10000

tx = mksend(inputs, outputs, addr, fee)

dt = deserialize(tx)
ins = dt['ins']

#print addr
#print ins


for ind, elm in enumerate(ins):
    print elm
    tx = sign(tx, ind, priv)

#print tx



print(pushtx(tx))
</code></pre>
 9382: <p>The script is simply (so to speak) taking a raw transaction and splicing in a hexadecimal number which represents an additional Tx output. So it's looking for <em>ffffffff</em> (<em>sequence</em>) and appending <code>6a</code> <code>hex encoding of your msg</code> (up to 20 bytes)</p>

<p>The message needs converting to hex (which the code does).</p>

<p>The code works fine for me, although I've yet to try broadcasting. Based on your quoted error </p>

<blockquote>
  <p><em>I get the error (from the Blockchain.info broadcast API): Exception: None Standard Script Output OP_RETURN 594f4c4f53574147</em></p>
</blockquote>

<p>I'd have to say BCI is reacting to the<code>MessageLen</code> part of the code. There should be an <code>OP_PUSHDATA1</code> (<code>0x4c</code>) between <code>OP_RETURN</code> (<code>0x6a</code>) and the 1 byte msg length, <code>0x08</code>. </p>

<p>Try: <code>6a4c08594f4c4f53574147</code></p>

<p>Alternatively, try another service to push the raw Tx, eg:</p>

<ul>
<li><a href="https://insight.bitpay.com/tx/send" rel="nofollow">https://insight.bitpay.com/tx/send</a></li>
<li><a href="https://brainwallet.github.io/#tx" rel="nofollow">https://brainwallet.github.io/#tx</a></li>
</ul>
 9382: <p>I have forked the <a href="https://github.com/vbuterin/pybitcointools" rel="nofollow noreferrer" title="pybitcointools">pybitcointools library</a> to return a properly formatted <code>OP_RETURN</code> hex string, or insert the <code>OP_RETURN</code> into a raw hex transaction.</p>

<p><a href="https://github.com/simcity4242/pybitcointools" rel="nofollow noreferrer">My fork can be found here</a>. The code is as follows:</p>

<pre><code>from bitcoin.pyspecials import safe_hexlify, from_string_to_bytes, from_int_to_byte, from_string_to_bytes

def mk_opreturn(msg, rawtx=None, json=0):
    def op_push(data):
        import struct
        if len(data) &lt; 0x4c:
            return from_int_to_byte(len(data)) + from_string_to_bytes(data)
        elif len(data) &lt; 0xff:
            return from_int_to_byte(76) + struct.pack('&lt;B', len(data)) + from_string_to_bytes(data)
        elif len(data) &lt; 0xffff:
            return from_int_to_byte(77) + struct.pack('&lt;H', len(data)) + from_string_to_bytes(data)
        elif len(data) &lt; 0xffffffff:
            return from_int_to_byte(78) + struct.pack('&lt;I', len(data)) + from_string_to_bytes(data)
        else: raise Exception("Input data error. Rawtx must be hex chars" \
                            + "0xffffffff &gt; len(data) &gt; 0")

    orhex = safe_hexlify(b'\x6a' + op_push(msg))
    orjson = {'script' : orhex, 'value' : 0}
    if rawtx is not None:
        try:
            txo = deserialize(rawtx)
            if not 'outs' in txo.keys(): raise Exception("OP_Return cannot be the sole output!")
            txo['outs'].append(orjson)
            newrawtx = serialize(txo)
            return newrawtx
        except:
            raise Exception("Raw Tx Error!")
    return orhex if not json else orjson
</code></pre>

<p>Note that the module name has been changed to <code>btc</code> (from <code>bitcoin</code>) in my fork. </p>

<p>To run this, you'll use <code>os.chdir("c:/python/pybitcointools")</code> (or whatever directory it's been downloaded to. Then <code>from bitcoin import *</code>. Now, let's use <code>msg = 'The enemy of my enemy is my friend'</code> and <code>rawtx = "01000000016e3cd2b24fcf49259db29888ec5fe6521070041cb8c7bb2017537046f9e00f2b0000000000ffffffff0168d61100000000001976a91469bbbb16301e40b9fb67130e1aa53a2281d60af088ac00000000"</code>.</p>

<p><code>mk_opreturn(msg, rawtx)</code> returns: </p>

<pre><code>01000000016e3cd2b24fcf49259db29888ec5fe6521070041cb8c7bb2017537046f9e00f2b0000000000ffffffff0268d61100000000001976a91469bbbb16301e40b9fb67130e1aa53a2281d60af088ac0000000000000000246a2254686520656e656d79206f66206d7920656e656d79206973206d7920667269656e6400000000
</code></pre>

<p>This is the raw Tx with the <code>OP_RETURN</code> properly inserted. Run the function without the <code>rawtx</code> parameter and it returns the string <code>6a2254686520656e656d79206f66206d7920656e656d79206973206d7920667269656e64</code></p>
