omergertel / pyformance

Performance metrics, based on Coda Hale's Yammer metrics
Other
195 stars 72 forks source link

Fix reporting to OpenTSDB in Python3 #40

Closed RendijsSmukulis closed 7 years ago

RendijsSmukulis commented 7 years ago

urllib2 in python2 expects data as a string, while urllib in python3 expects a byte array. This change ensures we encode the string if running in python 3.

This fixes https://github.com/omergertel/pyformance/issues/39

omergertel commented 7 years ago

What happens if we always encode in 'UTF-8'? Would that work in python2?

RendijsSmukulis commented 7 years ago

That'll work too. In Python2 it'll still be a string, but each character will be encoded in an 8 bit representation (so 1 or more bytes), so it's essentially same as a byte array (which is one and the same in py2, not so much in py3). Thanks for looking at this, I'll update the pull request in a moment!

omergertel commented 7 years ago

Cool, thanks! I don't like checking for versions if we can avoid it :)

RendijsSmukulis commented 7 years ago

Hi!

Do you think this can be merged in the current state, or is there any other work required?

omergertel commented 7 years ago

Yes, thank you!