frozenpandaman / splatnet2statink

Takes battle data from the SplatNet 2 app and uploads it to stat.ink
https://github.com/frozenpandaman/splatnet2statink/wiki
347 stars 61 forks source link

ascii decode issue #85

Closed vlee489 closed 5 years ago

vlee489 commented 5 years ago

Trying to upload battles using the -r parm and I get thrown this error

Vincents-MacBook-Pro:splatnet2statink vlee489$ python2 splatnet2statink.py -r
splatnet2statink v1.5.0
Checking if there are previously-unuploaded battles...
Previously-unuploaded battles detected. Uploading now...
Traceback (most recent call last):
  File "splatnet2statink.py", line 1271, in <module>
    populate_battles(is_s, is_t, is_r, debug)
  File "splatnet2statink.py", line 371, in populate_battles
    post_battle(0, [result], s_flag, t_flag, -1, True if i == 0 else False, debug, False)
  File "splatnet2statink.py", line 776, in post_battle
    payload["uuid"] = str(uuid.uuid5(namespace, name))
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/uuid.py", line 603, in uuid5
    hash = sha1(namespace.bytes + name).digest()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcf in position 1: ordinal not in range(128)
frozenpandaman commented 5 years ago

uuuugggghhh unicode. also ugh python 2.

Related: #84

What is your in-game nickname?

Can look more into this later.

vlee489 commented 5 years ago

Yeah, I had a look at it earlier. There's a proper way in python 3 to deal with this issue, but it's a bit of a mess in python 2.

I mean it's probably time this tool gets rewritten for Python 3 with the fact python 2 is reaching its end of life in 6 months.

vlee489 commented 5 years ago

uuuugggghhh unicode. also ugh python 2.

Related: #84

What is your in-game nickname?

Can look more into this later.

my ign is: я»Vincent

That я»will likely be the issue.

frozenpandaman commented 5 years ago

it's probably time this tool gets rewritten for Python 3

You can use it with Python 3, and have been able to for a while. :)

vlee489 commented 5 years ago

Ah, my pip3 install was broken, hence I was missing dependencies, but I've ran it in python 3 and it works fine. If it's an issue related to Python 2, then there isn't much to worry about, I would just explicitly say at this point that this tool needs to run in python 3.

frozenpandaman commented 5 years ago

Yeah, I originally wanted to make the script as accessible to as many people as possible and therefore was thinking people could use this with the default Python 2 install that came with macOS. But Python 3 is heavily encouraged. We just used future to have both supported (for now).

With Python 2 nearing its EOL, as you said, plus with the announcement at WWDC this week that future versions of macOS won't even ship with Python at all, I agree we shouldn't really have to keep supporting it. However, there isn't really much active development on this script anymore (as the game & presumably app are essentially done with updates) – and IMO it'd be great to be able to fix this error if possible, just so it does work fully in Python 2, in perpetuity... 😬

gomtuu commented 5 years ago

I ran into the same problem with Python 2.7.9. Did a quick Google search and found this issue that looked relevant. So I changed:

payload["uuid"] = str(uuid.uuid5(namespace, name))

to:

payload["uuid"] = str(uuid.uuid5(namespace, name.encode('ascii')))

and it worked.

But that probably won't work in Python 3, so you'd need to detect the version, I guess.

Edit: I think it's worth pointing out that the name variable referenced above isn't the player's in-game name; it's constructed from two ID numbers connected by an @ symbol. So converting it to ASCII for Python 2 compatibility should always be safe, I think.

frozenpandaman commented 5 years ago

Oh, weird. So nicknames aren't coming into this at all… I don't really understand the source of the error, then, and I'm not able to reproduce it. Shouldn't name always be a string, no matter the Python version? It's just made of the format battle_number (also a string) + "@" + principal_id (also a string) after all… Based on the bug @gomtuu linked, it seems this is the fault of the uuid module?

I'll just fix it by checking the Python version, I guess – I don't see any better/more-elegant way.

frozenpandaman commented 5 years ago

@vlee489 @gomtuu Can you confirm this works? Thanks!

gomtuu commented 5 years ago

Works for me! Thanks!