vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

Python3 urllib required POST data to be in bytes #179

Closed omdv closed 6 years ago

omdv commented 6 years ago

How to verify - run the example posted on README with python3. When at last step, i.e. trying to pushtx() I receive:

Exception                                 Traceback (most recent call last)
<ipython-input-8-8648951e913e> in <module>()
----> 1 pushtx(tx2)

/usr/local/lib/python3.6/site-packages/bitcoin/bci.py in pushtx(*args, **kwargs)
    302 def pushtx(*args, **kwargs):
    303     f = pushtx_getters.get(kwargs.get('source', ''), bci_pushtx)
--> 304     return f(*args)
    305
    306

/usr/local/lib/python3.6/site-packages/bitcoin/bci.py in bci_pushtx(tx)
    257     if not re.match('^[0-9a-fA-F]*$', tx):
    258         tx = tx.encode('hex')
--> 259     return make_request('https://blockchain.info/pushtx', 'tx='+tx)
    260
    261

/usr/local/lib/python3.6/site-packages/bitcoin/bci.py in make_request(*args)
     21         except:
     22             p = e
---> 23         raise Exception(p)
     24
     25

Exception: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

The fix is easy, I believe - encode the string for the python3 usage. Will validate and propose the PR.

omdv commented 6 years ago

Nevermind, this issue is gone in the current git version. It is however still in place if I install using official pip repository - might want to push it to pypi at some point.